ABAP Select data from SAP table BAPI1084IN 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 BAPI1084IN 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 BAPI1084IN. 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 BAPI1084IN 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_BAPI1084IN TYPE STANDARD TABLE OF BAPI1084IN, WA_BAPI1084IN TYPE BAPI1084IN, 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: <BAPI1084IN> TYPE BAPI1084IN. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_BAPI1084IN. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM BAPI1084IN INTO TABLE IT_BAPI1084IN. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM BAPI1084IN * INTO TABLE @DATA(IT_BAPI1084IN2). *--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_BAPI1084IN INDEX 1 INTO DATA(WA_BAPI1084IN2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_BAPI1084IN ASSIGNING <BAPI1084IN>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<BAPI1084IN>-EXT_PAT_ID = 1.
<BAPI1084IN>-LAST_NAME_PAT = 1.
<BAPI1084IN>-FRST_NAME_PAT = 1.
<BAPI1084IN>-BIRTH_NAME = 1.
<BAPI1084IN>-DOB = 1.
ENDLOOP. LOOP AT IT_BAPI1084IN INTO WA_BAPI1084IN. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_BAPI1084IN-BIRTHCTRY, sy-vline,
WA_BAPI1084IN-BIRTHCTRY_ISO, sy-vline,
WA_BAPI1084IN-BIRTHPLACE, sy-vline,
WA_BAPI1084IN-SEX_EXT, sy-vline,
WA_BAPI1084IN-PSEUDO, sy-vline,
WA_BAPI1084IN-FORM_ADDRS_STXT, sy-vline.
ENDLOOP. *Add any further fields from structure WA_BAPI1084IN 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_BAPI1084IN 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_BAPI1084IN INTO WA_BAPI1084IN. *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 PAT_ADDR_NO CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPI1084IN-PAT_ADDR_NO IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI1084IN-PAT_ADDR_NO.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field PAT_ADDR2_NO CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPI1084IN-PAT_ADDR2_NO IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI1084IN-PAT_ADDR2_NO.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ISOLA, internal->external for field PAT_LANGU CALL FUNCTION 'CONVERSION_EXIT_ISOLA_OUTPUT' EXPORTING input = WA_BAPI1084IN-PAT_LANGU IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI1084IN-PAT_LANGU.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field RACE CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPI1084IN-RACE IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI1084IN-RACE.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field DOC_TYPE CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPI1084IN-DOC_TYPE IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI1084IN-DOC_TYPE.
WRITE:/ 'New Value:', ld_input.
*Conversion exit NLJUS, internal->external for field DOC_NO CALL FUNCTION 'CONVERSION_EXIT_NLJUS_OUTPUT' EXPORTING input = WA_BAPI1084IN-DOC_NO IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI1084IN-DOC_NO.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field EMPLOYERID CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPI1084IN-EMPLOYERID IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI1084IN-EMPLOYERID.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field EMP_ADDR_NO CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPI1084IN-EMP_ADDR_NO IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI1084IN-EMP_ADDR_NO.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field CONTACTP1_ADDRNO CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPI1084IN-CONTACTP1_ADDRNO IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI1084IN-CONTACTP1_ADDRNO.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field CONTACTP2_ADDRNO CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPI1084IN-CONTACTP2_ADDRNO IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI1084IN-CONTACTP2_ADDRNO.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field FAM_PHYS CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPI1084IN-FAM_PHYS IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI1084IN-FAM_PHYS.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field REF_PHYS CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPI1084IN-REF_PHYS IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI1084IN-REF_PHYS.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field REF_PHYS2 CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPI1084IN-REF_PHYS2 IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI1084IN-REF_PHYS2.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field POST_DIS_PHYS CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPI1084IN-POST_DIS_PHYS IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI1084IN-POST_DIS_PHYS.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field POST_DIS_PHYS_OUTP CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPI1084IN-POST_DIS_PHYS_OUTP IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI1084IN-POST_DIS_PHYS_OUTP.
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_BAPI1084IN_STR,
EXT_PAT_ID TYPE STRING,
LAST_NAME_PAT TYPE STRING,
FRST_NAME_PAT TYPE STRING,
BIRTH_NAME TYPE STRING,
DOB TYPE STRING,
BIRTHCTRY TYPE STRING,
BIRTHCTRY_ISO TYPE STRING,
BIRTHPLACE TYPE STRING,
SEX_EXT TYPE STRING,
PSEUDO TYPE STRING,
FORM_ADDRS_STXT TYPE STRING,
TITLE TYPE STRING,
AFFIX TYPE STRING,
PREFIX TYPE STRING,
PAT_ADDR_NO TYPE STRING,
PAT_ADDR2_NO TYPE STRING,
MAR_STAT_TEXT TYPE STRING,
REL_DENOM_STXT TYPE STRING,
NATIONALITY TYPE STRING,
PAT_LANGU TYPE STRING,
PAT_LANGU_ISO TYPE STRING,
ORGAN_DONOR TYPE STRING,
VIP TYPE STRING,
EXPIRED TYPE STRING,
DT_O_DEATH_FROM TYPE STRING,
TM_O_DEATH_FROM TYPE STRING,
DT_O_DEATH_TO TYPE STRING,
TM_O_DEATH_TO TYPE STRING,
C_OF_DEATH TYPE STRING,
EMERG_ADM TYPE STRING,
QUICK_ADM TYPE STRING,
NON_RESIDENT TYPE STRING,
INACTIVE TYPE STRING,
PUBLISTBLOCK TYPE STRING,
RELIG_LIST TYPE STRING,
PARISH TYPE STRING,
RACE TYPE STRING,
SSN TYPE STRING,
DOC_TYPE TYPE STRING,
DOC_NO TYPE STRING,
OCCUPATION TYPE STRING,
EMPLOYERID TYPE STRING,
EMP_NAME TYPE STRING,
EMP_ADDR_NO TYPE STRING,
CONTACTP1_LNAME TYPE STRING,
CONTACTP1_FNAME TYPE STRING,
CONTACTP1_RELSH TYPE STRING,
CONTACTP1_LGLREP TYPE STRING,
CONTACTP1_EXTID TYPE STRING,
CONTACTP1_ADDRNO TYPE STRING,
CONTACTP2_LNAME TYPE STRING,
CONTACTP2_FNAME TYPE STRING,
CONTACTP2_RELSH TYPE STRING,
CONTACTP2_LGLREP TYPE STRING,
CONTACTP2_EXTID TYPE STRING,
CONTACTP2_ADDRNO TYPE STRING,
FAM_PHYS TYPE STRING,
REF_PHYS TYPE STRING,
REF_PHYS2 TYPE STRING,
USER1 TYPE STRING,
USER2 TYPE STRING,
USER3 TYPE STRING,
USER4 TYPE STRING,
USER5 TYPE STRING,
USER6 TYPE STRING,
CREATION_DATE TYPE STRING,
CREATION_USER TYPE STRING,
EMPLOYED_SINCE TYPE STRING,
ISTAT_BIRTHPL TYPE STRING,
TAXNUMBER TYPE STRING,
TAXNUMBER_INDIC TYPE STRING,
STPCODE TYPE STRING,
STPCODE_EXPIRY TYPE STRING,
CONSENT_PERSDATA TYPE STRING,
BIRTH_RANK TYPE STRING,
FLAG_EXT_ORDERER TYPE STRING,
DTH_LOC TYPE STRING,
POST_DIS_PHYS TYPE STRING,
POST_DIS_PHYS_OUTP TYPE STRING,END OF T_EKKO_STR. DATA: WA_BAPI1084IN_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_BAPI1084IN_STR-EXT_PAT_ID sy-vline
WA_BAPI1084IN_STR-LAST_NAME_PAT sy-vline
WA_BAPI1084IN_STR-FRST_NAME_PAT sy-vline
WA_BAPI1084IN_STR-BIRTH_NAME sy-vline
WA_BAPI1084IN_STR-DOB sy-vline
WA_BAPI1084IN_STR-BIRTHCTRY sy-vline
WA_BAPI1084IN_STR-BIRTHCTRY_ISO sy-vline
WA_BAPI1084IN_STR-BIRTHPLACE sy-vline
WA_BAPI1084IN_STR-SEX_EXT sy-vline
WA_BAPI1084IN_STR-PSEUDO sy-vline
WA_BAPI1084IN_STR-FORM_ADDRS_STXT sy-vline
WA_BAPI1084IN_STR-TITLE sy-vline
WA_BAPI1084IN_STR-AFFIX sy-vline
WA_BAPI1084IN_STR-PREFIX sy-vline
WA_BAPI1084IN_STR-PAT_ADDR_NO sy-vline
WA_BAPI1084IN_STR-PAT_ADDR2_NO sy-vline
WA_BAPI1084IN_STR-MAR_STAT_TEXT sy-vline
WA_BAPI1084IN_STR-REL_DENOM_STXT sy-vline
WA_BAPI1084IN_STR-NATIONALITY sy-vline
WA_BAPI1084IN_STR-PAT_LANGU sy-vline
WA_BAPI1084IN_STR-PAT_LANGU_ISO sy-vline
WA_BAPI1084IN_STR-ORGAN_DONOR sy-vline
WA_BAPI1084IN_STR-VIP sy-vline
WA_BAPI1084IN_STR-EXPIRED sy-vline
WA_BAPI1084IN_STR-DT_O_DEATH_FROM sy-vline
WA_BAPI1084IN_STR-TM_O_DEATH_FROM sy-vline
WA_BAPI1084IN_STR-DT_O_DEATH_TO sy-vline
WA_BAPI1084IN_STR-TM_O_DEATH_TO sy-vline
WA_BAPI1084IN_STR-C_OF_DEATH sy-vline
WA_BAPI1084IN_STR-EMERG_ADM sy-vline
WA_BAPI1084IN_STR-QUICK_ADM sy-vline
WA_BAPI1084IN_STR-NON_RESIDENT sy-vline
WA_BAPI1084IN_STR-INACTIVE sy-vline
WA_BAPI1084IN_STR-PUBLISTBLOCK sy-vline
WA_BAPI1084IN_STR-RELIG_LIST sy-vline
WA_BAPI1084IN_STR-PARISH sy-vline
WA_BAPI1084IN_STR-RACE sy-vline
WA_BAPI1084IN_STR-SSN sy-vline
WA_BAPI1084IN_STR-DOC_TYPE sy-vline
WA_BAPI1084IN_STR-DOC_NO sy-vline
WA_BAPI1084IN_STR-OCCUPATION sy-vline
WA_BAPI1084IN_STR-EMPLOYERID sy-vline
WA_BAPI1084IN_STR-EMP_NAME sy-vline
WA_BAPI1084IN_STR-EMP_ADDR_NO sy-vline
WA_BAPI1084IN_STR-CONTACTP1_LNAME sy-vline
WA_BAPI1084IN_STR-CONTACTP1_FNAME sy-vline
WA_BAPI1084IN_STR-CONTACTP1_RELSH sy-vline
WA_BAPI1084IN_STR-CONTACTP1_LGLREP sy-vline
WA_BAPI1084IN_STR-CONTACTP1_EXTID sy-vline
WA_BAPI1084IN_STR-CONTACTP1_ADDRNO sy-vline
WA_BAPI1084IN_STR-CONTACTP2_LNAME sy-vline
WA_BAPI1084IN_STR-CONTACTP2_FNAME sy-vline
WA_BAPI1084IN_STR-CONTACTP2_RELSH sy-vline
WA_BAPI1084IN_STR-CONTACTP2_LGLREP sy-vline
WA_BAPI1084IN_STR-CONTACTP2_EXTID sy-vline
WA_BAPI1084IN_STR-CONTACTP2_ADDRNO sy-vline
WA_BAPI1084IN_STR-FAM_PHYS sy-vline
WA_BAPI1084IN_STR-REF_PHYS sy-vline
WA_BAPI1084IN_STR-REF_PHYS2 sy-vline
WA_BAPI1084IN_STR-USER1 sy-vline
WA_BAPI1084IN_STR-USER2 sy-vline
WA_BAPI1084IN_STR-USER3 sy-vline
WA_BAPI1084IN_STR-USER4 sy-vline
WA_BAPI1084IN_STR-USER5 sy-vline
WA_BAPI1084IN_STR-USER6 sy-vline
WA_BAPI1084IN_STR-CREATION_DATE sy-vline
WA_BAPI1084IN_STR-CREATION_USER sy-vline
WA_BAPI1084IN_STR-EMPLOYED_SINCE sy-vline
WA_BAPI1084IN_STR-ISTAT_BIRTHPL sy-vline
WA_BAPI1084IN_STR-TAXNUMBER sy-vline
WA_BAPI1084IN_STR-TAXNUMBER_INDIC sy-vline
WA_BAPI1084IN_STR-STPCODE sy-vline
WA_BAPI1084IN_STR-STPCODE_EXPIRY sy-vline
WA_BAPI1084IN_STR-CONSENT_PERSDATA sy-vline
WA_BAPI1084IN_STR-BIRTH_RANK sy-vline
WA_BAPI1084IN_STR-FLAG_EXT_ORDERER sy-vline
WA_BAPI1084IN_STR-DTH_LOC sy-vline
WA_BAPI1084IN_STR-POST_DIS_PHYS sy-vline
WA_BAPI1084IN_STR-POST_DIS_PHYS_OUTP sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.