ABAP Select data from SAP table P1890_EXP 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 P1890_EXP 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 P1890_EXP. 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 P1890_EXP 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_P1890_EXP TYPE STANDARD TABLE OF P1890_EXP,
      WA_P1890_EXP TYPE P1890_EXP,
      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: <P1890_EXP> TYPE P1890_EXP.

*Process all fields in table header/work area as string values
  PERFORM process_as_string_field_values CHANGING wa_P1890_EXP.

SELECT *
*restrict ABAP select to first 10 rows
 UP TO 10 ROWS      
  FROM P1890_EXP
  INTO TABLE IT_P1890_EXP.

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM P1890_EXP
*  INTO TABLE @DATA(IT_P1890_EXP2).
*--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_P1890_EXP INDEX 1 INTO DATA(WA_P1890_EXP2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_P1890_EXP ASSIGNING <P1890_EXP>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<P1890_EXP>-MANDT = 1.
<P1890_EXP>-PLVAR = 1.
<P1890_EXP>-OTYPE = 1.
<P1890_EXP>-OBJID = 1.
<P1890_EXP>-INFTY = 1.
ENDLOOP.

LOOP AT IT_P1890_EXP INTO WA_P1890_EXP.
*Write horizonal line to screen report.
  WRITE:/ sy-uline.

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_P1890_EXP-SUBTY, sy-vline,
WA_P1890_EXP-ISTAT, sy-vline,
WA_P1890_EXP-PRIOX, sy-vline,
WA_P1890_EXP-BEGDA, sy-vline,
WA_P1890_EXP-ENDDA, sy-vline,
WA_P1890_EXP-VARYF, sy-vline.
ENDLOOP. *Add any further fields from structure WA_P1890_EXP 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_P1890_EXP 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_P1890_EXP INTO WA_P1890_EXP. *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 OPBEL CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_P1890_EXP-OPBEL IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_P1890_EXP-OPBEL.
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_P1890_EXP_STR,
MANDT TYPE STRING,
PLVAR TYPE STRING,
OTYPE TYPE STRING,
OBJID TYPE STRING,
INFTY TYPE STRING,
SUBTY TYPE STRING,
ISTAT TYPE STRING,
PRIOX TYPE STRING,
BEGDA TYPE STRING,
ENDDA TYPE STRING,
VARYF TYPE STRING,
SEQNR TYPE STRING,
AEDTM TYPE STRING,
UNAME TYPE STRING,
REASN TYPE STRING,
HISTO TYPE STRING,
ITXNR TYPE STRING,
SC_OBJID TYPE STRING,
ADM_AYEAR TYPE STRING,
ADM_PERID TYPE STRING,
PAIDBY TYPE STRING,
PAYMENTTYPE TYPE STRING,
PAYMENTNAME TYPE STRING,
FORMOFPAYBANKDUT TYPE STRING,
FORMOFPAYBANKFOR TYPE STRING,
BANK TYPE STRING,
BANKCOUNTRY TYPE STRING,
INSTALLMENTS TYPE STRING,
PAID TYPE STRING,
AMOUNTFEE TYPE STRING,
PROOFFEEPAID TYPE STRING,
FEE_WAIVER TYPE STRING,
INVOICE TYPE STRING,
NOOFINST TYPE STRING,
ADMINFEE TYPE STRING,
BARCODE TYPE STRING,
ORDERNUM TYPE STRING,
PAIDATBRIN TYPE STRING,
PAIDATINST TYPE STRING,
DOCNR TYPE STRING,
AUTHFEEAMT TYPE STRING,
AUTHSENT TYPE STRING,
AUTHSTACC TYPE STRING,
AUTHWTDRW TYPE STRING,
AUTHSENTDATE TYPE STRING,
AUTHSENTTIME TYPE STRING,
OPBEL TYPE STRING,
ADM_GUID TYPE STRING,
PAID_INBRIN TYPE STRING,
BRIN_SEQ TYPE STRING,
PAID_INSTNAME TYPE STRING,
INITAMT TYPE STRING,
VALUTA_INIT TYPE STRING,
INSTAMT TYPE STRING,
VALUTA_INST TYPE STRING,
PRF_INSTATUS TYPE STRING,
RECEIV_BY TYPE STRING,
RECEIPT_DATE TYPE STRING,
INCANCEL_BY TYPE STRING,
INCANCEL_ON TYPE STRING,
TOTAL_AMT TYPE STRING,
VALUTA_TOT TYPE STRING,
INST_BRIN TYPE STRING,
PRF_OUTSTATUS TYPE STRING,
REG_BY TYPE STRING,
REG_DATE TYPE STRING,
OUTCANCEL_BY TYPE STRING,
OUTCANCEL_ON TYPE STRING,
LEGAL_TUTFEE TYPE STRING,
VALUTA_LEGLFEE TYPE STRING,
INST_TUTFEE TYPE STRING,
VALUTA_INSTFEE TYPE STRING,
IBAN TYPE STRING,
MAND_REFID TYPE STRING,
BIC TYPE STRING,
EMANDATE_IND TYPE STRING,
AUTHISSUE_REUSEDATE TYPE STRING,
TABNR TYPE STRING,
TABSEQNR TYPE STRING,
INSTNUMBER TYPE STRING,
DUE_DATE TYPE STRING,END OF T_EKKO_STR. DATA: WA_P1890_EXP_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_P1890_EXP_STR-MANDT sy-vline
WA_P1890_EXP_STR-PLVAR sy-vline
WA_P1890_EXP_STR-OTYPE sy-vline
WA_P1890_EXP_STR-OBJID sy-vline
WA_P1890_EXP_STR-INFTY sy-vline
WA_P1890_EXP_STR-SUBTY sy-vline
WA_P1890_EXP_STR-ISTAT sy-vline
WA_P1890_EXP_STR-PRIOX sy-vline
WA_P1890_EXP_STR-BEGDA sy-vline
WA_P1890_EXP_STR-ENDDA sy-vline
WA_P1890_EXP_STR-VARYF sy-vline
WA_P1890_EXP_STR-SEQNR sy-vline
WA_P1890_EXP_STR-AEDTM sy-vline
WA_P1890_EXP_STR-UNAME sy-vline
WA_P1890_EXP_STR-REASN sy-vline
WA_P1890_EXP_STR-HISTO sy-vline
WA_P1890_EXP_STR-ITXNR sy-vline
WA_P1890_EXP_STR-SC_OBJID sy-vline
WA_P1890_EXP_STR-ADM_AYEAR sy-vline
WA_P1890_EXP_STR-ADM_PERID sy-vline
WA_P1890_EXP_STR-PAIDBY sy-vline
WA_P1890_EXP_STR-PAYMENTTYPE sy-vline
WA_P1890_EXP_STR-PAYMENTNAME sy-vline
WA_P1890_EXP_STR-FORMOFPAYBANKDUT sy-vline
WA_P1890_EXP_STR-FORMOFPAYBANKFOR sy-vline
WA_P1890_EXP_STR-BANK sy-vline
WA_P1890_EXP_STR-BANKCOUNTRY sy-vline
WA_P1890_EXP_STR-INSTALLMENTS sy-vline
WA_P1890_EXP_STR-PAID sy-vline
WA_P1890_EXP_STR-AMOUNTFEE sy-vline
WA_P1890_EXP_STR-PROOFFEEPAID sy-vline
WA_P1890_EXP_STR-FEE_WAIVER sy-vline
WA_P1890_EXP_STR-INVOICE sy-vline
WA_P1890_EXP_STR-NOOFINST sy-vline
WA_P1890_EXP_STR-ADMINFEE sy-vline
WA_P1890_EXP_STR-BARCODE sy-vline
WA_P1890_EXP_STR-ORDERNUM sy-vline
WA_P1890_EXP_STR-PAIDATBRIN sy-vline
WA_P1890_EXP_STR-PAIDATINST sy-vline
WA_P1890_EXP_STR-DOCNR sy-vline
WA_P1890_EXP_STR-AUTHFEEAMT sy-vline
WA_P1890_EXP_STR-AUTHSENT sy-vline
WA_P1890_EXP_STR-AUTHSTACC sy-vline
WA_P1890_EXP_STR-AUTHWTDRW sy-vline
WA_P1890_EXP_STR-AUTHSENTDATE sy-vline
WA_P1890_EXP_STR-AUTHSENTTIME sy-vline
WA_P1890_EXP_STR-OPBEL sy-vline
WA_P1890_EXP_STR-ADM_GUID sy-vline
WA_P1890_EXP_STR-PAID_INBRIN sy-vline
WA_P1890_EXP_STR-BRIN_SEQ sy-vline
WA_P1890_EXP_STR-PAID_INSTNAME sy-vline
WA_P1890_EXP_STR-INITAMT sy-vline
WA_P1890_EXP_STR-VALUTA_INIT sy-vline
WA_P1890_EXP_STR-INSTAMT sy-vline
WA_P1890_EXP_STR-VALUTA_INST sy-vline
WA_P1890_EXP_STR-PRF_INSTATUS sy-vline
WA_P1890_EXP_STR-RECEIV_BY sy-vline
WA_P1890_EXP_STR-RECEIPT_DATE sy-vline
WA_P1890_EXP_STR-INCANCEL_BY sy-vline
WA_P1890_EXP_STR-INCANCEL_ON sy-vline
WA_P1890_EXP_STR-TOTAL_AMT sy-vline
WA_P1890_EXP_STR-VALUTA_TOT sy-vline
WA_P1890_EXP_STR-INST_BRIN sy-vline
WA_P1890_EXP_STR-PRF_OUTSTATUS sy-vline
WA_P1890_EXP_STR-REG_BY sy-vline
WA_P1890_EXP_STR-REG_DATE sy-vline
WA_P1890_EXP_STR-OUTCANCEL_BY sy-vline
WA_P1890_EXP_STR-OUTCANCEL_ON sy-vline
WA_P1890_EXP_STR-LEGAL_TUTFEE sy-vline
WA_P1890_EXP_STR-VALUTA_LEGLFEE sy-vline
WA_P1890_EXP_STR-INST_TUTFEE sy-vline
WA_P1890_EXP_STR-VALUTA_INSTFEE sy-vline
WA_P1890_EXP_STR-IBAN sy-vline
WA_P1890_EXP_STR-MAND_REFID sy-vline
WA_P1890_EXP_STR-BIC sy-vline
WA_P1890_EXP_STR-EMANDATE_IND sy-vline
WA_P1890_EXP_STR-AUTHISSUE_REUSEDATE sy-vline
WA_P1890_EXP_STR-TABNR sy-vline
WA_P1890_EXP_STR-TABSEQNR sy-vline
WA_P1890_EXP_STR-INSTNUMBER sy-vline
WA_P1890_EXP_STR-DUE_DATE sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.