Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SAP RFC_READ_TEXT Usage

Status
Not open for further replies.

jbivin

Programmer
Mar 31, 2010
23
US
All,

I hate to keep posting things, but I have another SAP question. I am trying to pull longtext from SAP tables and can do it one part number and one operation at a time with the following code.

Code:
Public Sub ReadText()


  Set objFileSystemObject = VBA.CreateObject("Scripting.FileSystemObject")
  Set filOutput = objFileSystemObject.CreateTextFile("C:\Documents and Settings\jpbivin\Desktop\LTEXT2.CSV", True)

 
 Set RFC_READ_TEXT = funcControl.Add("RFC_READ_TEXT")
 Set tblText_Lines = RFC_READ_TEXT.Tables("TEXT_LINES")

 tblText_Lines.AppendRow
 tblText_Lines(1, "TDOBJECT") = "ROUTING"
 tblText_Lines(1, "TDNAME") = "005N503786180000000100000001"
 tblText_Lines(1, "TDID") = "PLPO"

 If RFC_READ_TEXT.Call = True Then
    
        If tblText_Lines.RowCount > 0 Then
    
    
            ' Change Next line to write a different header row
        
        
            filOutput.WriteLine "Object, LText"
        
        
            For intRow = 1 To tblText_Lines.RowCount
        
        
                filOutput.WriteLine   tblText_Lines(intRow, "TDLINE")
        
            Next
    
    
                MsgBox "COMPLETED SUCCESSFULLY"
                
            
        Else
        
        
            MsgBox "No records returned"
    
    
        End If



    Else


        MsgBox "ERROR CALLING SAP REMOTE FUNCTION CALL"


    End If

'Result Table set back
 Do Until tblText_Lines.RowCount = 0
     Call tblText_Lines.Rows.Remove(1)
 Loop

 Set tblText_Lines = Nothing


End Sub

If someone has a website that lists all the possible remote function calls (RFCs) for SAP and how they can be used then I can use that to work from because I have searched and cannot find one anywhere. Or if anyone has any suggestions regarding the question then that would be appreciated also.

Thanks for all your help. It is always appreciated.
 
Sorry, I didn't ask the question. I am needing to do multiple part numbers with all their operations at one time. Thanks.
 
No need to reply. I have a code that functions well. If anyone would like to improve upon or needs this code feel free to use it.

Code:
Dim LogonControl
Dim conn
Dim funcControl
Dim TableFactoryCtrl
Dim RFC_READ_TEXT
Dim eQUERY_TAB
Dim tblOptions
Dim tblData
Dim tblFields
Dim retcd
Dim strExport1
Dim strExport2
Dim intRow1 As Integer
Dim intRow2 As Integer
Dim intRow3 As Integer
Dim PartNumber() As String
Dim PN As String
Dim Operation() As String
Dim OP As String
Dim Group() As String
Dim Descrip() As String
Dim GroupCheck As String
Dim objFileSystemObject As Object
Dim filOutput As Object
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim LongText As String
Dim lngRecordCount As Long

Public Sub LogOn()

    Set LogonControl = VBA.CreateObject("SAP.LogonControl.1")
    Set funcControl = VBA.CreateObject("SAP.Functions")
    Set conn = LogonControl.NewConnection
    
    'Code To Connect To SAP
    
    conn.System = "PR1" ' System ID istanza,di solito 0
    conn.Client = "005" ' Client per logon to
    conn.Language = "EN" ' Lingua logon
    'conn.User = "JBIVIN" ' User ID
    'conn.Password = "Amber369" ' Password
    retcd = conn.LogOn(0, False)
      
    Select Case retcd
        
        Case False

            VBA.MsgBox "Cannot log on!", vbInformation + vbOKOnly, "Logon Failed"
            Set LogonControl = Nothing
            Set funcControl = Nothing
            Set conn = Nothing
            Exit Sub
    
        Case True

            funcControl.Connection = conn
            
                
                    Call ReadText
            
            Set LogonControl = Nothing
            Set funcControl = Nothing
            Set conn = Nothing
    
    End Select
    
End Sub

Public Sub Fill()

Dim rc As Recordset

i = 1

Set rc = CurrentDb.OpenRecordset("Export")

    lngRecordCount = 0
        
  With rc
  
    .MoveFirst
        
        On Error Resume Next
        Do Until rc.EOF
        
            ReDim Preserve PartNumber(i)
            ReDim Preserve Operation(i)
            ReDim Preserve Group(i)
            ReDim Preserve Descrip(i)
            
                PartNumber(i) = ![Mat]
                Operation(i) = ![WrkCnt]
                Group(i) = ![Grp]
                Descrip(i) = ![MatDesc]
                
          i = i + 1
                   
         .MoveNext
                       
        Loop

End With

    lngRecordCount = rc.RecordCount

rc.Close


End Sub


Public Sub ReadText()
  
Call Fill

  Set objFileSystemObject = VBA.CreateObject("Scripting.FileSystemObject")
  Set filOutput = objFileSystemObject.CreateTextFile("F:\Operations Improvement\Manufacturing Improvement\Interplant Material Delivery System\LTEXT2.CSV", True)

j = 1
k = 1

Do Until IsNull(PartNumber(j))
    
    
1
    
    
    filOutput.WriteLine PartNumber(j)
    filOutput.WriteLine Descrip(j)
    filOutput.WriteLine "Operation, LongText"
    
2
  
  LongText = "005N" & Group(j) & "0000000" & k & "0000000" & k
 
  Set RFC_READ_TEXT = funcControl.Add("RFC_READ_TEXT")
  Set tblText_Lines = RFC_READ_TEXT.Tables("TEXT_LINES")

    strExport1 = "STXL"
    strExport2 = " "
    
    tblText_Lines.AppendRow
    tblText_Lines(1, "TDOBJECT") = "ROUTING"
    tblText_Lines(1, "TDNAME") = LongText
    tblText_Lines(1, "TDID") = "PLPO"
      
 If RFC_READ_TEXT.Call = True Then
    
        If tblText_Lines.RowCount > 0 Then
    
    
            ' Change Next line to write a different header row
        
        intRow1 = 1
        
            For intRow1 = 1 To tblText_Lines.RowCount
                
                If intRow1 = 1 Then
                
                filOutput.WriteLine Operation(j) & Chr(44) & tblText_Lines(intRow1, "TDLINE")
                
                Else
                
                filOutput.WriteLine Chr(44) & tblText_Lines(intRow1, "TDLINE")
                
                End If
        
            Next
            
            
    
                'MsgBox "COMPLETED SUCCESSFULLY"
                
            
        Else
        
        
            MsgBox "No records returned"
    
    
        End If

    Else


        MsgBox "ERROR CALLING SAP REMOTE FUNCTION CALL"


    End If

 'Result Table set back
 Do Until tblText_Lines.RowCount = 0
     Call tblText_Lines.Rows.Remove(1)
 Loop

 Set tblText_Lines = Nothing

j = j + 1

    Select Case j
        Case Is > lngRecordCount
            Exit Do
    End Select

If Group(k) = Group(k + 1) Then
    
        k = k + 1
        
        GoTo 2
        
    Else
    
        k = 1
        
        GoTo 1
        
    End If
    
Loop

    VBA.MsgBox "Finished!", vbInformation + vbOKOnly, "Status"

End Sub

Thanks for everyone's help. You are always beneficial.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top