ABAP Select data from SAP table PRULNKCTINV into internal table
Get Example source ABAP code based on a different SAP table
Below is a number of ABAP code snippets to demonstrate how to select data from SAP PRULNKCTINV table and store it within an internal table, including using the newer @DATA inline declaration methods. It also shows you various ways to process this data using ABAP work area, inline declaration or field symbols including executing all the relevant CONVERSION_EXIT routines specific to PRULNKCTINV. See here for more generic Select statement tips.
Sometimes data within SAP is stored within the database table in a different format to what it is displayed to the user. These input/output conversation FM routines are what translates the data between the two formats.
There is also a full declaration of the PRULNKCTINV table where each field has a char/string type for you to simply copy and paste. This allows you to use processing that is only available to these field types such as the CONCATENATE statement.
DATA: IT_PRULNKCTINV TYPE STANDARD TABLE OF PRULNKCTINV, WA_PRULNKCTINV TYPE PRULNKCTINV, GD_STR TYPE STRING. DATA: lo_typedescr type REF TO cl_abap_typedescr. DATA: lv_fieldname type fieldname. FIELD-SYMBOLS: <FIELD> TYPE any. FIELD-SYMBOLS: <PRULNKCTINV> TYPE PRULNKCTINV. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_PRULNKCTINV. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM PRULNKCTINV INTO TABLE IT_PRULNKCTINV. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM PRULNKCTINV * INTO TABLE @DATA(IT_PRULNKCTINV2). *--Further methods of using ABAP code to select data from SAP database tables *You can also declare the header/work area using the in-line DATA declaration method READ TABLE IT_PRULNKCTINV INDEX 1 INTO DATA(WA_PRULNKCTINV2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_PRULNKCTINV ASSIGNING <PRULNKCTINV>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<PRULNKCTINV>-MANDT = 1.
<PRULNKCTINV>-INTERNALTABLEKEYFIELD = 1.
<PRULNKCTINV>-COMPANYCODE = 1.
<PRULNKCTINV>-ACCOUNTINGDOCUMENT = 1.
<PRULNKCTINV>-FISCALYEAR = 1.
ENDLOOP. LOOP AT IT_PRULNKCTINV INTO WA_PRULNKCTINV. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_PRULNKCTINV-POSTINGDATE, sy-vline,
WA_PRULNKCTINV-RU_REGISTRATIONINVOICEDATE, sy-vline,
WA_PRULNKCTINV-INVOICE, sy-vline,
WA_PRULNKCTINV-EXTERNALINVOICE, sy-vline,
WA_PRULNKCTINV-INVOICEYEAR, sy-vline,
WA_PRULNKCTINV-INVOICEDATE, sy-vline.
ENDLOOP. *Add any further fields from structure WA_PRULNKCTINV you want to display... WRITE:/ sy-uline. * Aternatively use generic code to Write field values (and NAME) to screen report DO. ASSIGN COMPONENT sy-index OF STRUCTURE wa_PRULNKCTINV TO <field>. IF sy-subrc <> 0. EXIT. ENDIF. WRITE:/ 'Field Value', <field>, sy-vline. gd_str = <field> . lo_typedescr ?= CL_ABAP_DATADESCR=>DESCRIBE_BY_DATA( <field> ). lv_fieldname = lo_typedescr->GET_RELATIVE_NAME( ). WRITE:/ 'Field Name', lv_fieldname. ENDDO. *Redo loop but convert all fields from internal to out value LOOP AT IT_PRULNKCTINV INTO WA_PRULNKCTINV. *Write horizonal line to screen report. WRITE:/ sy-uline. *Convert all fields to display/output versions using conversion routines PERFORM convert_all_field_values CHANGING wa_EKKO. ENDLOOP. *&---------------------------------------------------------------------* *& Form convert_all_field_values *&---------------------------------------------------------------------* FORM convert_all_field_values CHANGING p_EKKO LIKE wa_EKKO. DATA: ld_input(1000) TYPE c, ld_output(1000) TYPE C.
*Conversion exit ALPHA, internal->external for field ACCOUNTINGDOCUMENT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_PRULNKCTINV-ACCOUNTINGDOCUMENT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PRULNKCTINV-ACCOUNTINGDOCUMENT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit GJAHR, internal->external for field FISCALYEAR CALL FUNCTION 'CONVERSION_EXIT_GJAHR_OUTPUT' EXPORTING input = WA_PRULNKCTINV-FISCALYEAR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PRULNKCTINV-FISCALYEAR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field INVOICE CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_PRULNKCTINV-INVOICE IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PRULNKCTINV-INVOICE.
WRITE:/ 'New Value:', ld_input.
*Conversion exit GJAHR, internal->external for field INVOICEYEAR CALL FUNCTION 'CONVERSION_EXIT_GJAHR_OUTPUT' EXPORTING input = WA_PRULNKCTINV-INVOICEYEAR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PRULNKCTINV-INVOICEYEAR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field CORRECTIONINVOICE CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_PRULNKCTINV-CORRECTIONINVOICE IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PRULNKCTINV-CORRECTIONINVOICE.
WRITE:/ 'New Value:', ld_input.
*Conversion exit GJAHR, internal->external for field CORRECTIONINVOICEYEAR CALL FUNCTION 'CONVERSION_EXIT_GJAHR_OUTPUT' EXPORTING input = WA_PRULNKCTINV-CORRECTIONINVOICEYEAR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PRULNKCTINV-CORRECTIONINVOICEYEAR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field BUSINESSPARTNER CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_PRULNKCTINV-BUSINESSPARTNER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PRULNKCTINV-BUSINESSPARTNER.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field INCGINVOICEACCOUNTINGDOCUMENT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_PRULNKCTINV-INCGINVOICEACCOUNTINGDOCUMENT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PRULNKCTINV-INCGINVOICEACCOUNTINGDOCUMENT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit GJAHR, internal->external for field INCGINVOICEACCTGDOCFISCALYEAR CALL FUNCTION 'CONVERSION_EXIT_GJAHR_OUTPUT' EXPORTING input = WA_PRULNKCTINV-INCGINVOICEACCTGDOCFISCALYEAR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PRULNKCTINV-INCGINVOICEACCTGDOCFISCALYEAR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field RU_INCOMINGINVOICENUMBER CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_PRULNKCTINV-RU_INCOMINGINVOICENUMBER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PRULNKCTINV-RU_INCOMINGINVOICENUMBER.
WRITE:/ 'New Value:', ld_input.
*Conversion exit GJAHR, internal->external for field RU_INCOMINGINVOICEFISCALYEAR CALL FUNCTION 'CONVERSION_EXIT_GJAHR_OUTPUT' EXPORTING input = WA_PRULNKCTINV-RU_INCOMINGINVOICEFISCALYEAR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PRULNKCTINV-RU_INCOMINGINVOICEFISCALYEAR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field INCOMINGCORRECTIONINVOICE CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_PRULNKCTINV-INCOMINGCORRECTIONINVOICE IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PRULNKCTINV-INCOMINGCORRECTIONINVOICE.
WRITE:/ 'New Value:', ld_input.
*Conversion exit GJAHR, internal->external for field INCOMINGCORRECTIONINVOICEYEAR CALL FUNCTION 'CONVERSION_EXIT_GJAHR_OUTPUT' EXPORTING input = WA_PRULNKCTINV-INCOMINGCORRECTIONINVOICEYEAR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PRULNKCTINV-INCOMINGCORRECTIONINVOICEYEAR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field INCOMINGINVOICEBUSINESSPARTNER CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_PRULNKCTINV-INCOMINGINVOICEBUSINESSPARTNER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PRULNKCTINV-INCOMINGINVOICEBUSINESSPARTNER.
WRITE:/ 'New Value:', ld_input.
*Conversion exit AU132, internal->external for field COMMSNTRADEINVOICELINKEDAMOUNT CALL FUNCTION 'CONVERSION_EXIT_AU132_OUTPUT' EXPORTING input = WA_PRULNKCTINV-COMMSNTRADEINVOICELINKEDAMOUNT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PRULNKCTINV-COMMSNTRADEINVOICELINKEDAMOUNT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit AU132, internal->external for field COMMSNTRADEINVCLINKEDVATAMOUNT CALL FUNCTION 'CONVERSION_EXIT_AU132_OUTPUT' EXPORTING input = WA_PRULNKCTINV-COMMSNTRADEINVCLINKEDVATAMOUNT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PRULNKCTINV-COMMSNTRADEINVCLINKEDVATAMOUNT.
WRITE:/ 'New Value:', ld_input.
ENDFORM. *&---------------------------------------------------------------------* *& Form process_as_string_field_values *&---------------------------------------------------------------------* FORM process_as_string_field_values CHANGING p_EKKO LIKE wa_EKKO. TYPES: BEGIN OF T_PRULNKCTINV_STR,
MANDT TYPE STRING,
INTERNALTABLEKEYFIELD TYPE STRING,
COMPANYCODE TYPE STRING,
ACCOUNTINGDOCUMENT TYPE STRING,
FISCALYEAR TYPE STRING,
POSTINGDATE TYPE STRING,
RU_REGISTRATIONINVOICEDATE TYPE STRING,
INVOICE TYPE STRING,
EXTERNALINVOICE TYPE STRING,
INVOICEYEAR TYPE STRING,
INVOICEDATE TYPE STRING,
DOCUMENTDATE TYPE STRING,
ORIGINALINVOICEREVISIONNUMBER TYPE STRING,
ORIGINALINVOICEREVISIONDATE TYPE STRING,
CORRECTIONINVOICE TYPE STRING,
EXTERNALCORRECTIONINVOICE TYPE STRING,
CORRECTIONINVOICEDATE TYPE STRING,
VATCORRECTIONDOCUMENTDATE TYPE STRING,
CORRECTIONINVOICEYEAR TYPE STRING,
CORRECTIONINVOICEREVISIONNMBR TYPE STRING,
CORRECTIONINVOICEREVISIONDATE TYPE STRING,
AMOUNTINTRANSACTIONCURRENCY TYPE STRING,
TAXAMOUNT TYPE STRING,
TRANSACTIONCURRENCY TYPE STRING,
CONTRACTNUM TYPE STRING,
BUSINESSPARTNER TYPE STRING,
BUSINESSPARTNERNAME TYPE STRING,
ISREVERSED TYPE STRING,
CUSTOMERFINSAUTHORIZATIONGRP TYPE STRING,
CUSTOMERCOMPANYAUTHZNGROUP TYPE STRING,
SUPPLIERFINSAUTHORIZATIONGRP TYPE STRING,
SUPPLIERCOMPANYAUTHZNGROUP TYPE STRING,
RU_VATRETURNVERSION TYPE STRING,
RU_INCOMINGINVOICECOMPANYCODE TYPE STRING,
INCGINVOICEACCOUNTINGDOCUMENT TYPE STRING,
INCGINVOICEACCTGDOCFISCALYEAR TYPE STRING,
INCGINVOICEACCTGDOCPOSTINGDATE TYPE STRING,
INCGINVOICEREGISTRATIONDATE TYPE STRING,
RU_INCOMINGINVOICENUMBER TYPE STRING,
INCOMINGEXTERNALINVOICE TYPE STRING,
RU_INCOMINGINVOICEFISCALYEAR TYPE STRING,
RU_INCOMINGINVOICEDATE TYPE STRING,
VATINCOMINGDOCUMENTDATE TYPE STRING,
INCGORIGLINVOICEREVISIONNUMBER TYPE STRING,
INCGORIGINALINVCREVISIONDATE TYPE STRING,
INCOMINGCORRECTIONINVOICE TYPE STRING,
INCGEXTERNALCORRECTIONINVOICE TYPE STRING,
INCOMINGCORRECTIONINVOICEDATE TYPE STRING,
VATINCOMINGCORRECTIONDOCDATE TYPE STRING,
INCOMINGCORRECTIONINVOICEYEAR TYPE STRING,
INCGCORRECTIONINVCREVISIONNMBR TYPE STRING,
INCGCORRECTIONINVCREVISIONDATE TYPE STRING,
INCGINVOICEAMOUNTINTRANSCRCY TYPE STRING,
INCGINVOICEVATAMTINTRANSCRCY TYPE STRING,
INCOMINGINVOICETRANSCURRENCY TYPE STRING,
INCOMINGINVOICECONTRACTNUMBER TYPE STRING,
INCOMINGINVOICEBUSINESSPARTNER TYPE STRING,
INCGINVOICEBUSINESSPARTNERNAME TYPE STRING,
INCOMINGINVOICEISREVERSED TYPE STRING,
INCGINVOICECUSTOMERAUTHZNGROUP TYPE STRING,
INCGINVCCUSTOMERCOAUTHZNGROUP TYPE STRING,
INCGINVOICESUPPLIERAUTHZNGROUP TYPE STRING,
INCGINVCSUPPLIERCOAUTHZNGROUP TYPE STRING,
COMMSNTRADEINVOICELINKEDAMOUNT TYPE STRING,
COMMSNTRADEINVCLINKEDVATAMOUNT TYPE STRING,
COMMSNTRADEINVOICELINKINGCRCY TYPE STRING,END OF T_EKKO_STR. DATA: WA_PRULNKCTINV_STR type T_EKKO_STR. DATA: ld_text TYPE string. LOOP AT IT_EKKO INTO WA_EKKO. MOVE-CORRESPONDING wa_EKKO TO WA_EKKO_STR. CONCATENATE: sy-vline
WA_PRULNKCTINV_STR-MANDT sy-vline
WA_PRULNKCTINV_STR-INTERNALTABLEKEYFIELD sy-vline
WA_PRULNKCTINV_STR-COMPANYCODE sy-vline
WA_PRULNKCTINV_STR-ACCOUNTINGDOCUMENT sy-vline
WA_PRULNKCTINV_STR-FISCALYEAR sy-vline
WA_PRULNKCTINV_STR-POSTINGDATE sy-vline
WA_PRULNKCTINV_STR-RU_REGISTRATIONINVOICEDATE sy-vline
WA_PRULNKCTINV_STR-INVOICE sy-vline
WA_PRULNKCTINV_STR-EXTERNALINVOICE sy-vline
WA_PRULNKCTINV_STR-INVOICEYEAR sy-vline
WA_PRULNKCTINV_STR-INVOICEDATE sy-vline
WA_PRULNKCTINV_STR-DOCUMENTDATE sy-vline
WA_PRULNKCTINV_STR-ORIGINALINVOICEREVISIONNUMBER sy-vline
WA_PRULNKCTINV_STR-ORIGINALINVOICEREVISIONDATE sy-vline
WA_PRULNKCTINV_STR-CORRECTIONINVOICE sy-vline
WA_PRULNKCTINV_STR-EXTERNALCORRECTIONINVOICE sy-vline
WA_PRULNKCTINV_STR-CORRECTIONINVOICEDATE sy-vline
WA_PRULNKCTINV_STR-VATCORRECTIONDOCUMENTDATE sy-vline
WA_PRULNKCTINV_STR-CORRECTIONINVOICEYEAR sy-vline
WA_PRULNKCTINV_STR-CORRECTIONINVOICEREVISIONNMBR sy-vline
WA_PRULNKCTINV_STR-CORRECTIONINVOICEREVISIONDATE sy-vline
WA_PRULNKCTINV_STR-AMOUNTINTRANSACTIONCURRENCY sy-vline
WA_PRULNKCTINV_STR-TAXAMOUNT sy-vline
WA_PRULNKCTINV_STR-TRANSACTIONCURRENCY sy-vline
WA_PRULNKCTINV_STR-CONTRACTNUM sy-vline
WA_PRULNKCTINV_STR-BUSINESSPARTNER sy-vline
WA_PRULNKCTINV_STR-BUSINESSPARTNERNAME sy-vline
WA_PRULNKCTINV_STR-ISREVERSED sy-vline
WA_PRULNKCTINV_STR-CUSTOMERFINSAUTHORIZATIONGRP sy-vline
WA_PRULNKCTINV_STR-CUSTOMERCOMPANYAUTHZNGROUP sy-vline
WA_PRULNKCTINV_STR-SUPPLIERFINSAUTHORIZATIONGRP sy-vline
WA_PRULNKCTINV_STR-SUPPLIERCOMPANYAUTHZNGROUP sy-vline
WA_PRULNKCTINV_STR-RU_VATRETURNVERSION sy-vline
WA_PRULNKCTINV_STR-RU_INCOMINGINVOICECOMPANYCODE sy-vline
WA_PRULNKCTINV_STR-INCGINVOICEACCOUNTINGDOCUMENT sy-vline
WA_PRULNKCTINV_STR-INCGINVOICEACCTGDOCFISCALYEAR sy-vline
WA_PRULNKCTINV_STR-INCGINVOICEACCTGDOCPOSTINGDATE sy-vline
WA_PRULNKCTINV_STR-INCGINVOICEREGISTRATIONDATE sy-vline
WA_PRULNKCTINV_STR-RU_INCOMINGINVOICENUMBER sy-vline
WA_PRULNKCTINV_STR-INCOMINGEXTERNALINVOICE sy-vline
WA_PRULNKCTINV_STR-RU_INCOMINGINVOICEFISCALYEAR sy-vline
WA_PRULNKCTINV_STR-RU_INCOMINGINVOICEDATE sy-vline
WA_PRULNKCTINV_STR-VATINCOMINGDOCUMENTDATE sy-vline
WA_PRULNKCTINV_STR-INCGORIGLINVOICEREVISIONNUMBER sy-vline
WA_PRULNKCTINV_STR-INCGORIGINALINVCREVISIONDATE sy-vline
WA_PRULNKCTINV_STR-INCOMINGCORRECTIONINVOICE sy-vline
WA_PRULNKCTINV_STR-INCGEXTERNALCORRECTIONINVOICE sy-vline
WA_PRULNKCTINV_STR-INCOMINGCORRECTIONINVOICEDATE sy-vline
WA_PRULNKCTINV_STR-VATINCOMINGCORRECTIONDOCDATE sy-vline
WA_PRULNKCTINV_STR-INCOMINGCORRECTIONINVOICEYEAR sy-vline
WA_PRULNKCTINV_STR-INCGCORRECTIONINVCREVISIONNMBR sy-vline
WA_PRULNKCTINV_STR-INCGCORRECTIONINVCREVISIONDATE sy-vline
WA_PRULNKCTINV_STR-INCGINVOICEAMOUNTINTRANSCRCY sy-vline
WA_PRULNKCTINV_STR-INCGINVOICEVATAMTINTRANSCRCY sy-vline
WA_PRULNKCTINV_STR-INCOMINGINVOICETRANSCURRENCY sy-vline
WA_PRULNKCTINV_STR-INCOMINGINVOICECONTRACTNUMBER sy-vline
WA_PRULNKCTINV_STR-INCOMINGINVOICEBUSINESSPARTNER sy-vline
WA_PRULNKCTINV_STR-INCGINVOICEBUSINESSPARTNERNAME sy-vline
WA_PRULNKCTINV_STR-INCOMINGINVOICEISREVERSED sy-vline
WA_PRULNKCTINV_STR-INCGINVOICECUSTOMERAUTHZNGROUP sy-vline
WA_PRULNKCTINV_STR-INCGINVCCUSTOMERCOAUTHZNGROUP sy-vline
WA_PRULNKCTINV_STR-INCGINVOICESUPPLIERAUTHZNGROUP sy-vline
WA_PRULNKCTINV_STR-INCGINVCSUPPLIERCOAUTHZNGROUP sy-vline
WA_PRULNKCTINV_STR-COMMSNTRADEINVOICELINKEDAMOUNT sy-vline
WA_PRULNKCTINV_STR-COMMSNTRADEINVCLINKEDVATAMOUNT sy-vline
WA_PRULNKCTINV_STR-COMMSNTRADEINVOICELINKINGCRCY sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.