ABAP Select data from SAP table OIUCM_CONTRACT_ST 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 OIUCM_CONTRACT_ST 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 OIUCM_CONTRACT_ST. 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 OIUCM_CONTRACT_ST 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_OIUCM_CONTRACT_ST TYPE STANDARD TABLE OF OIUCM_CONTRACT_ST, WA_OIUCM_CONTRACT_ST TYPE OIUCM_CONTRACT_ST, 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: <OIUCM_CONTRACT_ST> TYPE OIUCM_CONTRACT_ST. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_OIUCM_CONTRACT_ST. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM OIUCM_CONTRACT_ST INTO TABLE IT_OIUCM_CONTRACT_ST. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM OIUCM_CONTRACT_ST * INTO TABLE @DATA(IT_OIUCM_CONTRACT_ST2). *--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_OIUCM_CONTRACT_ST INDEX 1 INTO DATA(WA_OIUCM_CONTRACT_ST2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_OIUCM_CONTRACT_ST ASSIGNING <OIUCM_CONTRACT_ST>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<OIUCM_CONTRACT_ST>-MANDT = 1.
<OIUCM_CONTRACT_ST>-VBELN = 1.
<OIUCM_CONTRACT_ST>-ERDAT = 1.
<OIUCM_CONTRACT_ST>-ERZET = 1.
<OIUCM_CONTRACT_ST>-ERNAM = 1.
ENDLOOP. LOOP AT IT_OIUCM_CONTRACT_ST INTO WA_OIUCM_CONTRACT_ST. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_OIUCM_CONTRACT_ST-ANGDT, sy-vline,
WA_OIUCM_CONTRACT_ST-BNDDT, sy-vline,
WA_OIUCM_CONTRACT_ST-AUDAT, sy-vline,
WA_OIUCM_CONTRACT_ST-VBTYP, sy-vline,
WA_OIUCM_CONTRACT_ST-TRVOG, sy-vline,
WA_OIUCM_CONTRACT_ST-AUART, sy-vline.
ENDLOOP. *Add any further fields from structure WA_OIUCM_CONTRACT_ST 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_OIUCM_CONTRACT_ST 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_OIUCM_CONTRACT_ST INTO WA_OIUCM_CONTRACT_ST. *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 VBELN CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_OIUCM_CONTRACT_ST-VBELN IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_OIUCM_CONTRACT_ST-VBELN.
WRITE:/ 'New Value:', ld_input.
*Conversion exit AUART, internal->external for field AUART CALL FUNCTION 'CONVERSION_EXIT_AUART_OUTPUT' EXPORTING input = WA_OIUCM_CONTRACT_ST-AUART IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_OIUCM_CONTRACT_ST-AUART.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field KUNNR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_OIUCM_CONTRACT_ST-KUNNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_OIUCM_CONTRACT_ST-KUNNR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field OIU_PREV_CT_NO CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_OIUCM_CONTRACT_ST-OIU_PREV_CT_NO IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_OIUCM_CONTRACT_ST-OIU_PREV_CT_NO.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field OIU_GPLT_VNAME CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_OIUCM_CONTRACT_ST-OIU_GPLT_VNAME IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_OIUCM_CONTRACT_ST-OIU_GPLT_VNAME.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field OIU_GPLT_DOI_NO CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_OIUCM_CONTRACT_ST-OIU_GPLT_DOI_NO IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_OIUCM_CONTRACT_ST-OIU_GPLT_DOI_NO.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field OIU_MK_REP_NO CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_OIUCM_CONTRACT_ST-OIU_MK_REP_NO IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_OIUCM_CONTRACT_ST-OIU_MK_REP_NO.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field OIU_MK_REP_ISQ CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_OIUCM_CONTRACT_ST-OIU_MK_REP_ISQ IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_OIUCM_CONTRACT_ST-OIU_MK_REP_ISQ.
WRITE:/ 'New Value:', ld_input.
*Conversion exit MATN1, internal->external for field OIU_CON_MATNR CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT' EXPORTING input = WA_OIUCM_CONTRACT_ST-OIU_CON_MATNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_OIUCM_CONTRACT_ST-OIU_CON_MATNR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field MEINS CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_OIUCM_CONTRACT_ST-MEINS IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_OIUCM_CONTRACT_ST-MEINS.
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_OIUCM_CONTRACT_ST_STR,
MANDT TYPE STRING,
VBELN TYPE STRING,
ERDAT TYPE STRING,
ERZET TYPE STRING,
ERNAM TYPE STRING,
ANGDT TYPE STRING,
BNDDT TYPE STRING,
AUDAT TYPE STRING,
VBTYP TYPE STRING,
TRVOG TYPE STRING,
AUART TYPE STRING,
NETWR TYPE STRING,
WAERK TYPE STRING,
VKORG TYPE STRING,
VTWEG TYPE STRING,
SPART TYPE STRING,
GUEBG TYPE STRING,
GUEEN TYPE STRING,
KNUMV TYPE STRING,
VDATU TYPE STRING,
VPRGR TYPE STRING,
KALSM TYPE STRING,
FKARA TYPE STRING,
AWAHR TYPE STRING,
KTEXT TYPE STRING,
BSTNK TYPE STRING,
BSTDK TYPE STRING,
BNAME TYPE STRING,
KUNNR TYPE STRING,
STWAE TYPE STRING,
AEDAT TYPE STRING,
KOKRS TYPE STRING,
BUKRS_VF TYPE STRING,
ZTERM TYPE STRING,
PRSDT TYPE STRING,
OIU_CT_TYPE_CD TYPE STRING,
OIU_CUST_VEND_CD TYPE STRING,
OIU_APPR_FL TYPE STRING,
OIU_APPR_DT TYPE STRING,
OIU_EXEC_DT TYPE STRING,
OIU_STD_CT_FL TYPE STRING,
OIU_PREV_CT_NO TYPE STRING,
OIU_GPLT_COMPANY TYPE STRING,
OIU_GPLT_VNAME TYPE STRING,
OIU_GPLT_DOI_NO TYPE STRING,
OIU_MK_REP_NO TYPE STRING,
OIU_MK_REP_ISQ TYPE STRING,
OIU_DEST_SALE_CD TYPE STRING,
OIU_LIFE_LSE_FL TYPE STRING,
OIU_INV_NO TYPE STRING,
OIU_INV_FL TYPE STRING,
OIU_OBLIG_DT TYPE STRING,
OIU_DESK_CD TYPE STRING,
OIU_EIA_GINA_CD TYPE STRING,
OIU_CT_STATUS_CD TYPE STRING,
OIU_SPOT_TERM_CD TYPE STRING,
OIU_STNDEDQ_CD TYPE STRING,
OIU_IOTR_FL TYPE STRING,
OIU_INTRA_INTER TYPE STRING,
OIU_EXRES_SPLT TYPE STRING,
OIU_EVGN_FL TYPE STRING,
OIU_EVGNPD_BAS TYPE STRING,
OIU_EVGN_PERD_QY TYPE STRING,
OIU_PREIM_TM_CD TYPE STRING,
OIU_PRIM_TM_QY TYPE STRING,
OIU_SEC_TM_CD TYPE STRING,
OIU_SEC_TM_QY TYPE STRING,
OIU_EXP_NOTIF_DT TYPE STRING,
OIU_INTIT_RDT_DT TYPE STRING,
OIU_NEXT_RDT_DT TYPE STRING,
OIU_RTC_DT TYPE STRING,
OIU_RDT_N_PERD TYPE STRING,
OIU_RDT_REFQ_CD TYPE STRING,
OIU_RTF_CD TYPE STRING,
OIU_IMB_PRVSN_FL TYPE STRING,
OIU_FFEE_RMB_FL TYPE STRING,
OIU_FIRM_INTRPT TYPE STRING,
OIU_BAL_BAS_CD TYPE STRING,
OIU_PNTY_BAS_CD TYPE STRING,
OIU_TRANSP_BA TYPE STRING,
OIU_DLY_MAX_T_QY TYPE STRING,
OIU_PRCS_FL TYPE STRING,
OIU_SPR_FL TYPE STRING,
OIU_DEHYD_FL TYPE STRING,
OIU_COMPR_FL TYPE STRING,
OIU_PYMT_METH_CD TYPE STRING,
OIU_CON_MATNR TYPE STRING,
OIU_CON_MAX_QY TYPE STRING,
OIU_AFFIL_FL TYPE STRING,
OIU_MMS_TYPE_CD TYPE STRING,
OIU_MMS_ETPAY_FL TYPE STRING,
OIUH_CT_NO TYPE STRING,
OIU_CRUSER TYPE STRING,
OIU_TIMESTAMP TYPE STRING,
MEINS TYPE STRING,END OF T_EKKO_STR. DATA: WA_OIUCM_CONTRACT_ST_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_OIUCM_CONTRACT_ST_STR-MANDT sy-vline
WA_OIUCM_CONTRACT_ST_STR-VBELN sy-vline
WA_OIUCM_CONTRACT_ST_STR-ERDAT sy-vline
WA_OIUCM_CONTRACT_ST_STR-ERZET sy-vline
WA_OIUCM_CONTRACT_ST_STR-ERNAM sy-vline
WA_OIUCM_CONTRACT_ST_STR-ANGDT sy-vline
WA_OIUCM_CONTRACT_ST_STR-BNDDT sy-vline
WA_OIUCM_CONTRACT_ST_STR-AUDAT sy-vline
WA_OIUCM_CONTRACT_ST_STR-VBTYP sy-vline
WA_OIUCM_CONTRACT_ST_STR-TRVOG sy-vline
WA_OIUCM_CONTRACT_ST_STR-AUART sy-vline
WA_OIUCM_CONTRACT_ST_STR-NETWR sy-vline
WA_OIUCM_CONTRACT_ST_STR-WAERK sy-vline
WA_OIUCM_CONTRACT_ST_STR-VKORG sy-vline
WA_OIUCM_CONTRACT_ST_STR-VTWEG sy-vline
WA_OIUCM_CONTRACT_ST_STR-SPART sy-vline
WA_OIUCM_CONTRACT_ST_STR-GUEBG sy-vline
WA_OIUCM_CONTRACT_ST_STR-GUEEN sy-vline
WA_OIUCM_CONTRACT_ST_STR-KNUMV sy-vline
WA_OIUCM_CONTRACT_ST_STR-VDATU sy-vline
WA_OIUCM_CONTRACT_ST_STR-VPRGR sy-vline
WA_OIUCM_CONTRACT_ST_STR-KALSM sy-vline
WA_OIUCM_CONTRACT_ST_STR-FKARA sy-vline
WA_OIUCM_CONTRACT_ST_STR-AWAHR sy-vline
WA_OIUCM_CONTRACT_ST_STR-KTEXT sy-vline
WA_OIUCM_CONTRACT_ST_STR-BSTNK sy-vline
WA_OIUCM_CONTRACT_ST_STR-BSTDK sy-vline
WA_OIUCM_CONTRACT_ST_STR-BNAME sy-vline
WA_OIUCM_CONTRACT_ST_STR-KUNNR sy-vline
WA_OIUCM_CONTRACT_ST_STR-STWAE sy-vline
WA_OIUCM_CONTRACT_ST_STR-AEDAT sy-vline
WA_OIUCM_CONTRACT_ST_STR-KOKRS sy-vline
WA_OIUCM_CONTRACT_ST_STR-BUKRS_VF sy-vline
WA_OIUCM_CONTRACT_ST_STR-ZTERM sy-vline
WA_OIUCM_CONTRACT_ST_STR-PRSDT sy-vline
WA_OIUCM_CONTRACT_ST_STR-OIU_CT_TYPE_CD sy-vline
WA_OIUCM_CONTRACT_ST_STR-OIU_CUST_VEND_CD sy-vline
WA_OIUCM_CONTRACT_ST_STR-OIU_APPR_FL sy-vline
WA_OIUCM_CONTRACT_ST_STR-OIU_APPR_DT sy-vline
WA_OIUCM_CONTRACT_ST_STR-OIU_EXEC_DT sy-vline
WA_OIUCM_CONTRACT_ST_STR-OIU_STD_CT_FL sy-vline
WA_OIUCM_CONTRACT_ST_STR-OIU_PREV_CT_NO sy-vline
WA_OIUCM_CONTRACT_ST_STR-OIU_GPLT_COMPANY sy-vline
WA_OIUCM_CONTRACT_ST_STR-OIU_GPLT_VNAME sy-vline
WA_OIUCM_CONTRACT_ST_STR-OIU_GPLT_DOI_NO sy-vline
WA_OIUCM_CONTRACT_ST_STR-OIU_MK_REP_NO sy-vline
WA_OIUCM_CONTRACT_ST_STR-OIU_MK_REP_ISQ sy-vline
WA_OIUCM_CONTRACT_ST_STR-OIU_DEST_SALE_CD sy-vline
WA_OIUCM_CONTRACT_ST_STR-OIU_LIFE_LSE_FL sy-vline
WA_OIUCM_CONTRACT_ST_STR-OIU_INV_NO sy-vline
WA_OIUCM_CONTRACT_ST_STR-OIU_INV_FL sy-vline
WA_OIUCM_CONTRACT_ST_STR-OIU_OBLIG_DT sy-vline
WA_OIUCM_CONTRACT_ST_STR-OIU_DESK_CD sy-vline
WA_OIUCM_CONTRACT_ST_STR-OIU_EIA_GINA_CD sy-vline
WA_OIUCM_CONTRACT_ST_STR-OIU_CT_STATUS_CD sy-vline
WA_OIUCM_CONTRACT_ST_STR-OIU_SPOT_TERM_CD sy-vline
WA_OIUCM_CONTRACT_ST_STR-OIU_STNDEDQ_CD sy-vline
WA_OIUCM_CONTRACT_ST_STR-OIU_IOTR_FL sy-vline
WA_OIUCM_CONTRACT_ST_STR-OIU_INTRA_INTER sy-vline
WA_OIUCM_CONTRACT_ST_STR-OIU_EXRES_SPLT sy-vline
WA_OIUCM_CONTRACT_ST_STR-OIU_EVGN_FL sy-vline
WA_OIUCM_CONTRACT_ST_STR-OIU_EVGNPD_BAS sy-vline
WA_OIUCM_CONTRACT_ST_STR-OIU_EVGN_PERD_QY sy-vline
WA_OIUCM_CONTRACT_ST_STR-OIU_PREIM_TM_CD sy-vline
WA_OIUCM_CONTRACT_ST_STR-OIU_PRIM_TM_QY sy-vline
WA_OIUCM_CONTRACT_ST_STR-OIU_SEC_TM_CD sy-vline
WA_OIUCM_CONTRACT_ST_STR-OIU_SEC_TM_QY sy-vline
WA_OIUCM_CONTRACT_ST_STR-OIU_EXP_NOTIF_DT sy-vline
WA_OIUCM_CONTRACT_ST_STR-OIU_INTIT_RDT_DT sy-vline
WA_OIUCM_CONTRACT_ST_STR-OIU_NEXT_RDT_DT sy-vline
WA_OIUCM_CONTRACT_ST_STR-OIU_RTC_DT sy-vline
WA_OIUCM_CONTRACT_ST_STR-OIU_RDT_N_PERD sy-vline
WA_OIUCM_CONTRACT_ST_STR-OIU_RDT_REFQ_CD sy-vline
WA_OIUCM_CONTRACT_ST_STR-OIU_RTF_CD sy-vline
WA_OIUCM_CONTRACT_ST_STR-OIU_IMB_PRVSN_FL sy-vline
WA_OIUCM_CONTRACT_ST_STR-OIU_FFEE_RMB_FL sy-vline
WA_OIUCM_CONTRACT_ST_STR-OIU_FIRM_INTRPT sy-vline
WA_OIUCM_CONTRACT_ST_STR-OIU_BAL_BAS_CD sy-vline
WA_OIUCM_CONTRACT_ST_STR-OIU_PNTY_BAS_CD sy-vline
WA_OIUCM_CONTRACT_ST_STR-OIU_TRANSP_BA sy-vline
WA_OIUCM_CONTRACT_ST_STR-OIU_DLY_MAX_T_QY sy-vline
WA_OIUCM_CONTRACT_ST_STR-OIU_PRCS_FL sy-vline
WA_OIUCM_CONTRACT_ST_STR-OIU_SPR_FL sy-vline
WA_OIUCM_CONTRACT_ST_STR-OIU_DEHYD_FL sy-vline
WA_OIUCM_CONTRACT_ST_STR-OIU_COMPR_FL sy-vline
WA_OIUCM_CONTRACT_ST_STR-OIU_PYMT_METH_CD sy-vline
WA_OIUCM_CONTRACT_ST_STR-OIU_CON_MATNR sy-vline
WA_OIUCM_CONTRACT_ST_STR-OIU_CON_MAX_QY sy-vline
WA_OIUCM_CONTRACT_ST_STR-OIU_AFFIL_FL sy-vline
WA_OIUCM_CONTRACT_ST_STR-OIU_MMS_TYPE_CD sy-vline
WA_OIUCM_CONTRACT_ST_STR-OIU_MMS_ETPAY_FL sy-vline
WA_OIUCM_CONTRACT_ST_STR-OIUH_CT_NO sy-vline
WA_OIUCM_CONTRACT_ST_STR-OIU_CRUSER sy-vline
WA_OIUCM_CONTRACT_ST_STR-OIU_TIMESTAMP sy-vline
WA_OIUCM_CONTRACT_ST_STR-MEINS sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.