Open dataset string to date etc

Hi,
Task : Access data from application server and process it
issue : looks like everything has been treated as chars and I am not able to process anything but for same data if i send from presentation server it works perfectly alright.
i think i spend enough time to resolve this but couldn't get anything out of it.  please help me.
TYPES : BEGIN OF RECORD_IN,
          INVOICE_PSTNG_DATE      TYPE  BUDAT,
          INVOICE_DOC_DATE         TYPE  BLDAT,
          INOVICE_REF_DOC_NO       TYPE  XBLNR,
          GRECEIPT_PSTNG_DATE      TYPE  BUDAT,
          GRECEIPT_DOC_DATE        TYPE  BLDAT,
          GRECEIPT_REF_DOC_NO      TYPE  XBLNR,
          COMP_CODE                TYPE  BUKRS,
          GROSS_AMOUNT(27)         TYPE  C,
          DOC_DATE                 TYPE  EBDAT,
          AGREEMENT                TYPE  KONNR,
          PO_NUMBER                TYPE  BSTNR,
          PO_ITEM                  TYPE  EBELP,
          ENTRY_QNT(16)            TYPE  C,
          ITEM_FIELD_IND(1)        TYPE  C,
          DELIV_DATE               TYPE  EINDT,
        END OF RECORD_IN.
DATA  : IT_RECORD_IN      TYPE TABLE OF RECORD_IN.
FORM get_data_file.
Type-pools TRUXS.
  OPEN DATASET p_unxfil FOR INPUT IN TEXT MODE.
  IF sy-subrc = 0.
    DO.
      READ DATASET p_unxfil INTO input_file_tab-line_string.
      IF sy-subrc <> 0.
        EXIT.
      ENDIF.
      APPEND input_file_tab.
      CLEAR  input_file_tab.
    EDDO.
  ELSE.
    write :/ 'File read error'.
  ENDIF.
  data : lv_int type  i.
  loop at input_file_tab INTO input_file_tab-line_string.
    SPLIT input_file_tab-line_string at ',' into
              w_RECORD_IN-INVOICE_PSTNG_DATE
              w_RECORD_IN-INVOICE_DOC_DATE
              w_RECORD_IN-INOVICE_REF_DOC_NO
              w_RECORD_IN-GRECEIPT_PSTNG_DATE
              w_RECORD_IN-GRECEIPT_DOC_DATE
              w_RECORD_IN-GRECEIPT_REF_DOC_NO
              w_RECORD_IN-COMP_CODE
              w_RECORD_IN-GROSS_AMOUNT
              w_RECORD_IN-DOC_DATE
              w_RECORD_IN-AGREEMENT
              w_RECORD_IN-PO_NUMBER
              w_RECORD_IN-PO_ITEM
              w_RECORD_IN-ENTRY_QNT
              w_RECORD_IN-ITEM_FIELD_IND
              w_RECORD_IN-DELIV_DATE.
    lv_int = strlen( w_RECORD_IN-PO_ITEM ).
    lv_int  = 5 - lv_int.
    if lv_int > 0.
      do lv_int times.
        concatenate '0' w_RECORD_IN-PO_ITEM into w_RECORD_IN-PO_ITEM.
      enddo.
    endif.
    APPEND w_RECORD_IN to It_RECORD_IN.
  ENDLOOP.
  CLOSE DATASET p_unxfil.
Thanks
s

Hi Dude,
Use encoding default addition in open data set..
Example:
DATA: file   TYPE string VALUE `test.dat`,
          result TYPE string.
OPEN DATASET file FOR OUTPUT IN TEXT MODE
                               ENCODING DEFAULT
                               WITH SMART LINEFEED.
TRANSFER `1234567890` TO file.
CLOSE DATASET file.
OPEN DATASET file FOR UPDATE IN TEXT MODE
                               ENCODING DEFAULT
                               WITH SMART LINEFEED
                               AT POSITION 2.
TRANSFER `ABCD` TO file.
CLOSE DATASET file.
OPEN DATASET file FOR INPUT IN TEXT MODE
                               ENCODING DEFAULT
                               WITH SMART LINEFEED.
WHILE sy-subrc = 0.
  READ DATASET file INTO result.
  WRITE / result.
ENDWHILE.
CLOSE DATASET file.

Similar Messages

  • Reading any value from table into a string (Especially date etc..)

    How would I read any value from a table into a string?
    Currently doing the following...
    data ret_val type string.
    select single (wa_map-qes_field) from z_qekko into ret_val
    where
    angnr = _angnr.
    When the source field is a date it bombs though.
    The result goes into a BDCDATA-fval.
    regards
    Dylan.

    Tried...
    1    DATA: lp_data TYPE REF TO DATA.
    2    FIELD-SYMBOLS: <value> TYPE ANY.
    3    CREATE DATA lp_data LIKE (wa_map-qes_field).
    4    ASSIGN lp_data->* TO <value>.
    5    SELECT SINGLE (wa_map-qes_field) FROM zquadrem_qekko INTO <value> WHERE angnr = _angnr.
    Complains that (wa_map-qes_field) is not defined in line 3.
    Think that the bracket thing is only available via SQL.
    What about CREATE DATA lp_data type ref to object. ?
    Would the above declaration work?
    regards

  • OPEN DATASET FOR INPUT IN TEXT MODE - linesize issue

    Hi,
    I faced a problem when opened ANSI file with CYRILLIC in ECC 6.0 Unicode system - the system cuts the line to 250 characters. Below is snip of code:
    REPORT  Z_TEST_01 LINE-SIZE 1023.
    DATA:
      file TYPE char40 VALUE 'ansi_file.txt',
      line TYPE char1024, len TYPE i.
    OPEN DATASET file FOR INPUT IN TEXT MODE ENCODING DEFAULT.
    WHILE sy-subrc = 0.
          READ DATASET file INTO line ACTUAL LENGTH len.
            WRITE: / len, line.
    ENDWHILE.
    CLOSE DATASET file.
    In this case, variable LEN always get value 250. File-content is correctly converted from ANSI and all CYRILLIC is displayed to the screen. I changed type for LINE - initialy the type was STRING, actially.
    Further, tried to open it in BINARY - like this:
    DATA:
      file TYPE char40 VALUE 'ansi_file.txt',
      line TYPE char1024, len TYPE i.
    FIELD-SYMBOLS <hex_container> TYPE x.
    OPEN DATASET file FOR INPUT IN BINARY MODE.
    ASSIGN line TO <hex_container> CASTING.
    DO.
      READ DATASET file INTO <hex_container>.
      IF sy-subrc = 0.
        WRITE: / line.
      ELSE.
        EXIT.
      ENDIF.
    ENDDO.
    CLOSE DATASET file.
    WRITE: / line.
    In this case I got bigger linesize (obviously 1024), but faced conversion issues - the file contains some CYRILLIC and it is messed. Played for few hours with conversions - using additions: IN LEGACY BINARY MODE... BIG/LITTLE ENDIAN, CODE PAGE... without success. So decided to ask...
    Well, I searched SDN for a similar issue, but didn't found, except this one:
    Re: OPEN DATASET STRING Problem
    Could someone points me what am I doing wrong? How can I read my ANSI file with line-size more than 250 chars? Actually, in my case line size may vary up to 1800 chars. Further, afrer conversion and some validation, I should save it back to the AS.
    Many thans in advance.
    Regards,
    Ivaylo Mutafchiev

    Sorry for the noise - it is not an issue anymore.

  • OPEN DATASET - new line

    Hi Friends,
    I am facing a problem with OPEN DATASET to transfer data from XSTRING field to the text file.
    Then problem is like this I have a internal table type XSTRING. Which will have

    hi suresh,
    check this,
    data:
      begin of STRUC2,
        F1 type c,
        F2(20) type c,
      end of STRUC2.
    Put data into text format
    move-corresponding STRUC to STRUC2.
    Write data to file
    open dataset DSN in text mode for output encoding utf-8.
    transfer STRUC2 to DSN.
    close dataset DSN.
    Read data from file
    clear STRUC.
    open dataset DSN in text mode for input encoding utf-8.
    read dataset DSN into STRUC2.
    close dataset DSN.
    move-corresponding STRUC2 to STRUC.
    write: / STRUC-F1, STRUC-F2.
    The textual storage in UTF-8 format ensures that the created files are platform-independent.
    Case 2: Old non-Unicode format must be retained
    Write data to file
    open dataset DSN in legacy text mode for output.
    transfer STRUC to DSN.
    close dataset DSN.
    read from file
    clear STRUC.
    open dataset DSN in legacy text mode for input.
    read dataset DSN into STRUC.
    close dataset DSN.
    write: / STRUC-F1, STRUC-F2.

  • Merging data on a File created by Open Dataset

    Hi everyone
    I have 11 proxies writing on a FIle created by an Open Dataset (all of the proxies write on the same File).
    My customer sent massive messages to those proxies, when the proxies were running and writing on the file they merged the data.
    Can someone give me some light on how to prevent that merge without locking the file, cause if I lock the file the process is going to take too much time.
    Thanks in advanced
    Emmanuel

    why dont u have filename_proxyname
    each proxie will have diff names so they will not merge?

  • Open dataset in binary mode-data missing in pdf file

    Hi,
    I am downloading a pdf file to the appl server using the below code.
    open dataset filename for output in binary mode.
    OPEN DATASET file_name FOR OUTPUT IN BINARY MODE.
         LOOP AT lines INTO ls_lines.
           TRANSFER ls_lines TO file_name.
         ENDLOOP.
         CLOSE DATASET file_name.
         MESSAGE 'File has been Transfered' TYPE 'S'.
    pdf file is downloading to the appl server.
    I am reading the file using CG3Y transaction, an found that some tax values are missing.
    please advice on how to fix this issue ASAP.

    Pls find the code..
    In this case, the pdf file tax values are missing out as shown above screenshot..
    i also tried with legacy binary mode and binary mode code page 1100.
    * Convert OTF Data to pdf data
       CALL FUNCTION 'CONVERT_OTF'
         EXPORTING
           format                = 'PDF'
         IMPORTING
           bin_filesize          = pdf_size
         TABLES
           otf                   = ls_job_info-otfdata
           lines                 = lines
         EXCEPTIONS
           err_max_linewidth     = 1
           err_format            = 2
           err_conv_not_possible = 3
           err_bad_otf           = 4
           OTHERS                = 5.
       IF sy-subrc <> 0.
         MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                 WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
       ENDIF.
       LOOP AT lines INTO ls_lines.
         ASSIGN ls_lines TO <fs_x> CASTING.
         CONCATENATE lv_content <fs_x> INTO lv_content IN BYTE MODE.
       ENDLOOP.
    *  call SCREEN 9001.
       SHIFT wa_final1-vbeln LEFT DELETING LEADING '0'.
       SHIFT wa_final1-bstkd LEFT DELETING LEADING '0'.
       SHIFT wa_final1-kunnr LEFT DELETING LEADING '0'.
       IF sy-sysid = 'DEV' AND  sy-mandt = '046'.   " Development Server or Client.
         CONCATENATE 'E:\OrdAckNotfctn\Acknowledgements\' wa_final1-erdat
            '_' wa_final1-bstkd '_' wa_final1-vbeln '_' wa_final1-kunnr '.Pdf'
            INTO file_name.
         OPEN DATASET file_name FOR OUTPUT IN BINARY MODE. "TEXT MODE ENCODING DEFAULT.
         LOOP AT lines INTO ls_lines.
           TRANSFER ls_lines TO file_name.
         ENDLOOP.
         CLOSE DATASET file_name.
         MESSAGE 'File has been Transfered' TYPE 'S'.
       ELSEIF sy-sysid = 'SBX' AND  sy-mandt = '046'. " Testing Server or Client.
         CONCATENATE 'E:\OrdAckNotfctn\Acknowledgements\' wa_final1-erdat
              '_' wa_final1-bstkd '_' wa_final1-vbeln '_' wa_final1-kunnr '.Pdf'
              INTO file_name.
         OPEN DATASET file_name FOR OUTPUT IN LEGACY BINARY MODE. "TEXT MODE ENCODING DEFAULT.
         LOOP AT lines INTO ls_lines.
           TRANSFER ls_lines TO file_name.
         ENDLOOP.
         CLOSE DATASET file_name.
         MESSAGE 'File has been Transfered' TYPE 'S'.
       ELSEIF sy-sysid = 'PRD' AND  sy-mandt = '046'. " Production Server or Client.
         CONCATENATE 'E:\OrdAckNotfctn\Acknowledgements\' wa_final1-erdat
           '_' wa_final1-bstkd '_' wa_final1-vbeln '_' wa_final1-kunnr '.Pdf'
           INTO file_name.
         OPEN DATASET file_name FOR OUTPUT IN BINARY MODE. "TEXT MODE ENCODING DEFAULT.
         LOOP AT lines INTO ls_lines.
           TRANSFER ls_lines TO file_name.
         ENDLOOP.
         CLOSE DATASET file_name.
         MESSAGE 'File has been Transfered' TYPE 'S'.
       ENDIF.

  • Bad data added in Open Dataset for output in Binary mode

    Hello,
    I am getting random bad data being added to the end of the file that is created on the file server when I run the Open Dataset for output in Binary mode.  This data sometimes looks like information about the Unix file server.  If I do the Open Dataset in Text mode, it does not add the extra bad data.
    ** transfer file to Unix File server
           DATA: LIN TYPE P.
                                                                                    OPEN DATASET P_APPFIL FOR OUTPUT IN BINARY MODE.
                                                                                    DESCRIBE TABLE XML_TAB LINES LIN.
                                                                                    IF LIN EQ 0.
             EXIT.
           ELSE.
             LOOP AT XML_TAB.
               TRANSFER XML_TAB TO P_APPFIL.
             ENDLOOP.
           ENDIF.
                                                                                    CLOSE DATASET P_APPFIL.
    Running the program 2 times with the same variant will give different results.
    For example, the data in file should end with </cPedigreeXML> but it added data as shown below:
    </cPedigreeXML>8        ˜        I   X-UNKNOWN                                                 9            œ        I   X-UNKNOWN                                                10   
                C   X-UNKNOWN   
    Then, when the program was run again with the same selections, it did not add the erroneous data at the end.
    This is a real problem because the bad data that gets added causes the file to error in the application.  Any help would be greatly appreciated.
    Thanks,
    Bob

    Hi Bob,
          Use CLEAR statement after TRANSFER statement and check once.
         IF LIN EQ 0.
             EXIT.
           ELSE.
             LOOP AT XML_TAB.
               TRANSFER XML_TAB TO P_APPFIL.
               <b>CLEAR XML_TAB.</b>
             ENDLOOP.
           ENDIF.
    Thanks,
    Vinay

  • Transfering the data using OPEN DATASET

    Hi all,
    I am trying to get the data using OPEN DATASET to down load the data and using TRANSFER i am transfering.
    i got strucked while i am downloading.
    Please send coding how to use open dataset and transfer.
    Thanks in advance
    Venkat

    Hi ,
    you can try this code frangment.
    open the file to be created on application server.
      OPEN DATASET app_path FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
      IF sy-subrc NE 0.
        MESSAGE e001(zs) .
      ELSE.
    get header data
         PERFORM get_data_header.
    *transfer data to application server file.
        TRANSFER v_header TO app_path.
    get segment data
        PERFORM get_data_segment.
    *transfer data to application server file.
        TRANSFER v_segment TO app_path.
    *clear work areas and local variables.
        PERFORM clear_local.
    get trailer record.
        PERFORM get_data_trailer.
    *transfer data to application server file.
        TRANSFER v_trailer TO app_path.
      ENDIF.
      CLOSE DATASET app_path.
    regards,
    Sumit.

  • Data transfer error open dataset files

    hi,
    When i try to create a excel or text in my application server using open dataset.
    i.e
    l_filename type rlgrap-filename  value '/tmp/down.txt'.
    I got a short dump during the run time
    i got the output and put into an internal table.
    the following code has been used.
    form user_command using r_ucomm like sy-ucomm
    rs_selfield  type slis_selfield.
    if r_ucomm = 'confirm' .
    OPEN DATASET l_fname FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
    LOOP AT it_out INTO wa_out.
      IF sy-subrc = 0.
        TRANSFER wa_out TO l_filename.
      ENDIF.
    ENDLOOP.
    endform.
    during the execution i hv a button alv grid outpu. when i click the button the file should be transferred.
    but NO authorization to open the file "/tmp/down.txt".
    and the error is pointed in the opendataset line.
    Please tell me where i am wrong . and  help me in resoving this.

    Try this..instead of moving field by field into the file 1st convert all he fields to a character stream..and then move that steam to file. Ex:
    loop at internal table into l_h_tbl_file.
    concatenate l_h_tbl_file-f1 l_h_tbl_file-f2 l_h_tbl_file-f3
    l_h_tbl_file-f4 l_h_tbl_file-f5 into g_string.
    TRANSFER g_string TO fu_wk_get_file.
    endloop.

  • Open dataset......

    Hi Folks,
    I am trying to get some data using Open dataset.The program is not showing any errors and executing fine,but I was not able to find the data that I am going to get using OPEN DATASET.Where will I be able to see the data.In the given path there is no file downloaded.Kindly let me know.
    run the program
    enter some data in the blank fields of the alv
    save it
    now double click on the qty1 field in the alv.
    Thanks,
    K.Kiran.
    REPORT  zlabel.
    TYPE-POOLS:slis,icon.
    TABLES:makt.
    *Declarations for ALV
    DATA:itfieldcat TYPE slis_t_fieldcat_alv WITH HEADER LINE.
    DATA:itfieldcat1 TYPE slis_t_fieldcat_alv WITH HEADER LINE.
    DATA:itprintparams TYPE slis_print_alv.
    DATA:itrepid TYPE sy-repid.
    itrepid = sy-repid.
    DATA:itevent TYPE slis_t_event.
    DATA:itlistheader TYPE slis_t_listheader.
    DATA:walistheader LIKE LINE OF itlistheader.
    DATA:itlayout TYPE slis_layout_alv.
    DATA:top TYPE slis_formname.
    DATA:itsort TYPE slis_t_sortinfo_alv WITH HEADER LINE.
    DATA : grid  TYPE REF TO cl_gui_alv_grid.
    *Declaration for DSN
    <b>DATA : file(50) VALUE 'E:\userdata\labelfiles'.</b>
    DATA : dsn(150).
    DATA : dsn1(100).
    DATA : n1(4) TYPE n.
    *Declarations for Internal tables.
    DATA:BEGIN OF imakt OCCURS 0,
         matnr LIKE makt-matnr,
         spras LIKE makt-spras,
         maktx LIKE makt-maktx,
         label1(03) TYPE c,
         qty1(03) TYPE c,
         label2(03) TYPE c,
         qty2(03) TYPE c,
         END OF imakt.
    DATA:ITFINAL LIKE imakt OCCURS 0 WITH HEADER LINE.
    SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
    SELECT-OPTIONS:matnr FOR makt-matnr OBLIGATORY.
    SELECTION-SCREEN END OF BLOCK b1.
    START-OF-SELECTION.
    PERFORM getdata.
    IF sy-subrc = 0.
    PERFORM alv.
    ELSE.
    STOP.
    ENDIF.
    *&      Form  getdata
          text
    FORM getdata.
      SELECT matnr
             spras
             maktx
             FROM makt
             INTO CORRESPONDING FIELDS OF TABLE imakt
             WHERE spras = sy-langu.
    ENDFORM.                    "getdata
    *&      Form  ALV
          text
    FORM alv.
      DEFINE m_fieldcat.
        itfieldcat-fieldname = &1.
        itfieldcat-col_pos = &2.
        itfieldcat-seltext_l = &3.
        itfieldcat-do_sum = &4.
        itfieldcat-outputlen = &5.
        itfieldcat-edit = &6.
        append itfieldcat to itfieldcat.
        clear itfieldcat.
      END-OF-DEFINITION.
      m_fieldcat 'MATNR' '' 'MATERIAL No' '' 18 ''.
      m_fieldcat 'SPRAS' '' 'Language' '' 02 ''.
      m_fieldcat 'MAKTX' '' 'Description' '' 40 ''.
      m_fieldcat 'LABEL1' '' 'LABEL1' '' 12 'X'.
      m_fieldcat 'QTY1' '' 'QTY1' '' 12 'X'.
      m_fieldcat 'LABEL2' '' 'LABEL2' '' 12 'X'.
      m_fieldcat 'QTY2' '' 'QTY2' '' 12 'X'.
      itlayout-zebra = 'X'.
      itlayout-colwidth_optimize = 'X'.
      itlayout-no_subtotals = ' '.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
            EXPORTING
              i_callback_program      = sy-repid
              is_layout               = itlayout
           i_callback_pf_status_set = 'PF_STATUS'
              i_callback_user_command =  'LIST1'
              i_callback_top_of_page  = 'TOP'
              it_fieldcat             = itfieldcat[]
              i_save                  = 'X'
         is_variant              = ITVARIANT
              it_events               = itevent[]
            is_print                = itprintparams
              it_sort                 = itsort[]
            TABLES
              t_outtab                = imakt
              EXCEPTIONS
              program_error           = 1
              OTHERS                  = 2.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
      CLEAR itfieldcat.
    ENDFORM.                    "ALV
    *&      Form  list1
          text
         -->R_UCOMM    text
         -->RS_SELFIELDtext
    FORM list1 USING r_ucomm LIKE sy-ucomm
                      rs_selfield TYPE slis_selfield.
      CASE r_ucomm.
      WHEN 'EXIT'.
      STOP.
      ENDCASE.
      CLEAR itfieldcat1.
      REFRESH itfieldcat1.
      DEFINE k_fieldcat.
        itfieldcat1-fieldname = &1.
        itfieldcat1-col_pos = &2.
        itfieldcat1-seltext_l = &3.
        itfieldcat1-outputlen = &4.
        append itfieldcat1 to itfieldcat1.
        clear itfieldcat1.
      END-OF-DEFINITION.
      k_fieldcat 'MATNR' '' 'MATERIAL No' 18 .
      k_fieldcat 'SPRAS' '' 'Language'    02 .
      k_fieldcat 'MAKTX' '' 'Description' 40 .
      k_fieldcat 'LABEL1' '' 'LABEL1'     12 .
      k_fieldcat 'QTY1' '' 'QTY1' 12 .
      k_fieldcat 'LABEL2' '' 'LABEL2' 12 .
      k_fieldcat 'QTY2' '' 'QTY2' 12 .
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
            EXPORTING
              i_callback_program      = sy-repid
              is_layout               = itlayout
           i_callback_pf_status_set = 'PF_STATUS'
              i_callback_user_command =  'LIST2'
              i_callback_top_of_page  = 'TOP'
              it_fieldcat             = itfieldcat1[]
              i_save                  = 'X'
         is_variant              = ITVARIANT
              it_events               = itevent[]
            is_print                = itprintparams
              it_sort                 = itsort[]
            TABLES
              t_outtab                = imakt
              EXCEPTIONS
              program_error           = 1
              OTHERS                  = 2.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
      CLEAR:itfieldcat1,itfieldcat.
    ENDFORM.                                                    "list1
    *&      Form  list2
          text
         -->R_UCOMM    text
         -->RS_SELFIELDtext
    FORM list2 USING r_ucomm LIKE sy-ucomm
                      rs_selfield TYPE slis_selfield.
      CASE r_ucomm.
        WHEN '&IC1'.
        IF rs_selfield-fieldname = 'QTY1'.
        LOOP AT IMAKT.
        <b>CONCATENATE file n1 '.PJ' INTO dsn.</b>
       <b> PERFORM DSN.</b>  
       CLEAR DSN.
        N1 = N1 + 1.
        ENDLOOP.
        ENDIF.
    ENDCASE.
    ENDFORM.                                                    "list2
    *&      Form  top
          text
    FORM top.
      DATA:title(70) TYPE c.
      CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
           EXPORTING
              i_list_type           = 0
           IMPORTING
              et_events             = itevent
    EXCEPTIONS
      LIST_TYPE_WRONG       = 1
      OTHERS                = 2
      IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      title = 'LABEL'.
      walistheader-typ = 'H'.
      walistheader-info = title.
      APPEND walistheader TO itlistheader.
      CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
        EXPORTING
          it_list_commentary      = itlistheader
        I_LOGO                   = ''.
        I_END_OF_LIST_GRID       =
      CLEAR itlistheader.
    ENDFORM.                    "TOP
    *&      Form  DSN
          text
    -->  p1        text
    <--  p2        text
    <b>form DSN .</b>
    OPEN DATASET dsn FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
    IF sy-subrc <> 0.
    <b>LEAVE TO LIST-PROCESSING</b>
    <b>WRITE:/ 'FILE COULD NOT BE OPENED'.</b>
    EXIT.
    ENDIF.
    MOVE-CORRESPONDING IMAKT TO ITFINAL.
    APPEND ITFINAL.
    TRANSFER 'MDA.LBL' TO dsn.
    TRANSFER '1' TO dsn.
    TRANSFER: ITFINAL-MATNR TO DSN,
              ITFINAL-SPRAS TO DSN,
              ITFINAL-MAKTX TO DSN,
              ITFINAL-LABEL1 TO DSN,
              ITFINAL-QTY1 TO DSN,
              ITFINAL-LABEL2 TO DSN,
              ITFINAL-QTY2 TO DSN.
    <b>if sy-subrc <> 0.</b>
    write:/ 'Check your code'.
    endif.
    CLOSE DATASET DSN.
    ENDFORM.

    Hi Kiran,
    To my understanding your file is not being created cause you have not passed a location for your file to be put. Refer to my below code you see how its done.
    If you need more info let me know.
    TYPES DECLARATIONS                                                   *
    *Data type for Accounting Document Header Table
    TYPES: BEGIN OF gt_bkpf,
             bukrs TYPE bkpf-bukrs,      "Company Code
             belnr TYPE bkpf-belnr,      "Accounting Document Number
             gjahr TYPE bkpf-gjahr,      "Fiscal Year
             budat TYPE bkpf-budat,      "Posting Date
           END OF gt_bkpf.
    *Data type for Accounting Document Segment Table
    TYPES: BEGIN OF gt_bseg,
             bukrs TYPE bkpf-bukrs,        "Company Code
             belnr TYPE bkpf-belnr,        "Accounting Document Number
             gjahr TYPE bkpf-gjahr,        "Fiscal Year
             buzei TYPE bseg-buzei  ,      "Line Item
             shkzg TYPE bseg-shkzg  ,      "Debit/Credit Indicator
             wrbtr TYPE bseg-wrbtr  ,      "Amount in document currency
             kostl TYPE bseg-kostl  ,      "Cost Center
             aufnr TYPE bseg-aufnr  ,      "Project / Order Number
             hkont TYPE bseg-hkont  ,      "General Ledger Account Key
             prctr TYPE bseg-prctr  ,      "Profit Center
             segment  TYPE bseg-segment,      "Segment
             END OF gt_bseg.
    *Data type for Posting Summary Table of given file format
    TYPES: BEGIN OF gt_posting_summary,
             effective_date(10)  TYPE c,       "Date of last tuesday
             company_code(4)     TYPE c,       "Company Code
             gl_key(6)           TYPE c,       "General Ledger Account Key
             cost_centre(10)     TYPE c,       "Cost Center
             profit_centre(10)   TYPE c,       "Profit Center
             project(12)         TYPE c,       "Order Number
             segment(10)         TYPE c,       "Segment for Segmental Reporting
             amount(16)          TYPE c,       "Amount with minor denomination & debit/credit indicator
           END OF gt_posting_summary.
    INTERNAL TABLE DECLARATIONS                                          *
    DATA:
    *Internal table for Accounting Document Header Table
    gi_bkpf              TYPE STANDARD TABLE OF gt_bkpf,
    *Internal table for Accounting Document Segment Table
    gi_bseg              TYPE STANDARD TABLE OF gt_bseg,
    *Internal table for Posting Summary Table of given file format
    gi_posting_summary   TYPE STANDARD TABLE OF gt_posting_summary.
    RANGES DECLARATIONS                                                  *
    DATA:
    *Building ranges table for last saturday to current date
    gr_date  TYPE RANGE OF sy-datum.
    WORK AREA DECLARATIONS                                               *
    DATA:
    *Work area for Accounting Document Segment Table
    gwa_bseg              TYPE gt_bseg,
    *Work area for Accounting Document Segment Table
    gwa_bkpf              TYPE gt_bkpf,
    *Work area for Posting Summary Table of given file format
    gwa_posting_summary   TYPE gt_posting_summary,
    *Work area for ranges table for last saturday to current date
    gwa_date              LIKE LINE  OF gr_date.
    GLOBAL VARIABLE DECLARATIONS                                         *
    DATA: gv_to_date            TYPE sy-datum,
          gv_from_date          TYPE sy-datum,
          gv_effective_date(10) TYPE c,
          gv_posting_amount(16) TYPE c,
          gv_file_name          TYPE string,
          gv_server_file_name   TYPE fileextern,
          gv_suspense_accnt     TYPE hkont,
          gv_amount             TYPE wrbtr.
    GLOBAL CONSTANT DECLARATIONS                                         *
    DATA: gc_x                    TYPE c                     VALUE 'X',
          gc_s                    TYPE bseg-shkzg            VALUE 'S',
          gc_h                    TYPE bseg-shkzg            VALUE 'H',
          gc_i                    TYPE tvarv-sign            VALUE 'I',
          gc_bt                   TYPE tvarv-opti            VALUE 'BT',
          gc_ys                   TYPE bkpf-blart            VALUE 'YS',
          gc_zfii0431             TYPE filepath-pathintern   VALUE 'ZFII0431',
          gc_debit                TYPE c                     VALUE '+',
          gc_credit               TYPE c                     VALUE '-',
          gc_dot                  TYPE c                     VALUE '.',
          gc_suspense_key         TYPE zglkey                VALUE 'SUSPENSE_GL_ACCOUNT'.
       Selection Screen                                                 *
    SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-t01.
    SELECTION-SCREEN SKIP 1.
    *Accounting Document type for eSFA postings
    PARAMETERS       :  p_ys             TYPE bkpf-blart DEFAULT gc_ys.
    SELECTION-SCREEN SKIP 1.
    *Logical Path of file to be downloaded on Application Server
    PARAMETERS       :  p_l_path         TYPE filepath-pathintern DEFAULT gc_zfii0431.
    SELECTION-SCREEN END OF BLOCK b1.
    SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-t02.
    SELECT-OPTIONS  :  s_date FOR sy-datum .
    SELECTION-SCREEN END OF BLOCK b2.
    ON LOAD EVENT         - Occurs only once, when the program is loaded *
    LOAD-OF-PROGRAM.
    ************************MAIN PROGRAM************************
    START-OF-SELECTION            - start of database access             *
    START-OF-SELECTION.
    Clear all global variables
      PERFORM clear_memory.
    Routine for calulating date of Last Saturday and Current Tuesday
      PERFORM calculate_posting_dates.
    Routine to select posted G/L records from database
      PERFORM posting_record_selection.
    Routine to compile posting summary table
      PERFORM build_posting_summary.
    Routine to make filename as eSFA_GL_CandC_YYYYMMDD.txt
      PERFORM build_file_name.
    Routine for compile physical path of file on Appln. Server
    from logical path and desired filename.
      PERFORM get_physical_path USING  p_l_path
                                       gv_file_name
                                       gc_x
                             CHANGING  gv_server_file_name.
    Routine to download file on application server
      PERFORM download_on_application_server.
    **************************INCLUDES***************************
      INCLUDE zfi_get_physical_path.
      INCLUDE zfi_file_status_change.
    *************************SUBROUTINES*************************
    *&     Form  calculate_posting_dates
         Routine for calulating date of Last Saturday and Current Tuesday
    FORM calculate_posting_dates .
      DATA: lv_monday    TYPE sy-datum.
    *Get the first day of the week.
      CALL FUNCTION 'BWSO_DATE_GET_FIRST_WEEKDAY'
        EXPORTING
          date_in  = sy-datum
        IMPORTING
          date_out = lv_monday.
    *Calculate the  to date (saturday)
      gv_to_date   =  lv_monday - 2.
    *Calculate the from date (sunday)
      gv_from_date =  lv_monday - 8.
      IF s_date-low IS NOT INITIAL.
        gv_from_date = s_date-low.
      ENDIF.
      IF s_date-high IS NOT INITIAL.
        gv_to_date = s_date-high.
      ENDIF.
    ENDFORM.                    " calculate_posting_dates
    *&      Form  build_posting_summary
          Routine for processing posting summary data table & compile
          in given output file table
    FORM build_posting_summary .
      DATA : lv_kostl      TYPE kostl,
             lv_amount     TYPE wrbtr,
             lv_amount_str TYPE wrbtr.
      DATA : li_posting_summary  TYPE TABLE OF gt_posting_summary.
      DATA : lwa_posting_summary TYPE gt_posting_summary.
      LOOP AT gi_bseg INTO gwa_bseg.
        READ TABLE gi_bkpf INTO gwa_bkpf
             WITH KEY bukrs = gwa_bseg-bukrs
                      belnr = gwa_bseg-belnr
                      gjahr = gwa_bseg-gjahr.
      Routine to calcualte effective date in format YYYY-MM-DD
        PERFORM calculate_effective_date.
        gwa_posting_summary-effective_date =  gv_effective_date.
        gwa_posting_summary-company_code   =  gwa_bseg-bukrs.
        gwa_posting_summary-gl_key         =  gwa_bseg-hkont+4(6).
        gwa_posting_summary-cost_centre    =  gwa_bseg-kostl.
        gwa_posting_summary-profit_centre  =  gwa_bseg-prctr.
        gwa_posting_summary-project        =  gwa_bseg-aufnr.
        gwa_posting_summary-segment        =  gwa_bseg-segment.
      Remove the derived fields created in SAP while posting
        IF gwa_bseg-kostl IS NOT INITIAL OR
           gwa_bseg-aufnr IS NOT INITIAL.
          CLEAR: gwa_posting_summary-profit_centre,
                 gwa_posting_summary-segment.
        ENDIF.
        IF gwa_bseg-aufnr IS NOT INITIAL.
      Substitution for internal order to costcenter for document type 'YS'
          SELECT SINGLE cost_centre
                   INTO lv_kostl
                   FROM ztfi_sub_costctr
                  WHERE internal_order = gwa_bseg-aufnr.
          IF sy-subrc = 0.
            gwa_posting_summary-cost_centre = lv_kostl.
            CLEAR gwa_posting_summary-project.
          ENDIF.
        ENDIF.
        IF gwa_bseg-shkzg = gc_h.
          gwa_bseg-wrbtr = gwa_bseg-wrbtr * -1.
          gwa_posting_summary-amount = gwa_bseg-wrbtr.
        ELSE.
          gwa_posting_summary-amount = gwa_bseg-wrbtr.
        ENDIF.
        APPEND gwa_posting_summary TO gi_posting_summary.
        CLEAR gwa_posting_summary.
        CLEAR gwa_bseg.
      ENDLOOP.        "LOOP AT gi_bseg INTO gwa_bseg
    Sort to find the summary
      SORT gi_posting_summary BY company_code
                                 gl_key
                                 cost_centre
                                 profit_centre
                                 project
                                 segment.
    *Summarise amount for unique entries
      LOOP AT gi_posting_summary INTO gwa_posting_summary.
        lv_amount_str = gwa_posting_summary-amount.
        lv_amount = lv_amount + lv_amount_str.
        AT END OF segment.
          gv_amount = lv_amount.
          PERFORM calculate_amount.
          gwa_posting_summary-amount = gv_posting_amount.
          APPEND gwa_posting_summary TO li_posting_summary.
          CLEAR lv_amount.
        ENDAT.
      ENDLOOP.
    *Copy the summarised table back to summary table
      gi_posting_summary = li_posting_summary.
    ENDFORM.                    " build_posting_summary
    *&      Form  calculate_effective_date
          Routine to calcualte effective date in format YYYY-MM-DD
    FORM calculate_effective_date .
      DATA: lv_date(8)            TYPE c,
            lv_yyyy(4)            TYPE c,
            lv_mm(2)              TYPE c,
            lv_dd(2)              TYPE c,
            lv_effective_date(10) TYPE c.
      DATA: lc_dash               TYPE c VALUE '-'.
      lv_date = gv_to_date.
      lv_yyyy = lv_date+0(4).
      lv_mm   = lv_date+4(2).
      lv_dd   = lv_date+6(2).
      CONCATENATE lv_yyyy
                  lc_dash
                  lv_mm
                  lc_dash
                  lv_dd
             INTO lv_effective_date.
      gv_effective_date = lv_effective_date.
    ENDFORM.                    " calculate_effective_date
    *&      Form  posting_record_selection
          Routine to select posted G/L records from database
    FORM posting_record_selection .
      gwa_date-sign   = gc_i.
      gwa_date-option = gc_bt.
      gwa_date-low    = gv_from_date.
      gwa_date-high   = gv_to_date.
      APPEND gwa_date TO gr_date.
    *Get the suspese GL accout number from ZTFI_SIXPARTKEY table.
      SELECT SINGLE gl_account
              FROM ztfi_sixpartkey
              INTO gv_suspense_accnt
            WHERE sixpartkey = gc_suspense_key .
      IF sy-subrc IS INITIAL.
    Selection of records (other than suspended acc. no. 999999) posted
    between last saturday and current tuesday where document type is 'YS'
        SELECT bukrs       "Company Code
               belnr       "Accounting Document Number
               gjahr       "Fiscal Year
               budat       "Posting Date
          FROM bkpf
          INTO TABLE gi_bkpf
          WHERE blart EQ p_ys
            AND budat IN gr_date.           "Change - MV - 16.04.2007 - FCDK902208
           AND cpudt IN gr_date.
        IF sy-subrc IS NOT INITIAL.
          WRITE / 'No records for current posting period, file not created.'(m03).
        ELSEIF sy-subrc IS INITIAL.
          READ TABLE gi_bkpf INTO gwa_bkpf INDEX 1.
          IF sy-subrc = 0.
            PERFORM calculate_effective_date.
          ENDIF.
      Selection of details of all records selected in above table
          SELECT bukrs          "Company Code
                 belnr          "Document Number
                 gjahr          "fiscal year
                 buzei          "Line Item
                 shkzg          "Debit/Credit Indicator
                 wrbtr          "Amount in document currency
                 kostl          "Cost Center
                 aufnr          "Project / Order Number
                 hkont          "General Ledger Account Key
                 prctr          "Profit Center
                 segment        "Segment
            FROM bseg
            INTO TABLE gi_bseg
            FOR ALL ENTRIES IN gi_bkpf
            WHERE bukrs = gi_bkpf-bukrs
              AND belnr = gi_bkpf-belnr
              AND gjahr = gi_bkpf-gjahr
              AND hkont <> gv_suspense_accnt.
          IF sy-subrc IS NOT INITIAL.
            WRITE / 'No records Found, file not created.'(002).
          ENDIF.
        ENDIF.
      ELSE.
        WRITE / 'Suspense GL account is not maintained in sixpart key look up table'(001).
      ENDIF.
    ENDFORM.                    " posting_record_selection
    *&      Form  calculate_amount
          Routine to concancate amouunt and debit/credit indicator
    FORM calculate_amount .
      DATA: lv_amount(15)   TYPE c,
            lv_amount_1(12)  TYPE c,
            lv_amount_2(2)  TYPE c,
            lv_debit_credit TYPE c.
      IF gv_amount <= 0.
        lv_debit_credit = gc_credit.
        gv_amount = gv_amount * -1.
      ELSE.
        lv_debit_credit = gc_debit.
      ENDIF.
      lv_amount  = gv_amount.
      SPLIT lv_amount AT gc_dot
                    INTO lv_amount_1
                         lv_amount_2.
      CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
        EXPORTING
          input  = lv_amount_1
        IMPORTING
          output = lv_amount_1.
      CONCATENATE lv_amount_1
                  lv_amount_2
             INTO lv_amount
      SEPARATED BY gc_dot.
      CONCATENATE  lv_debit_credit lv_amount INTO gv_posting_amount.
    ENDFORM.                    " calculate_amount
    *&      Form  build_file_name
          Routine to make filename as eSFA_GL_CandC_YYYYMMDD.txt
    FORM build_file_name .
      DATA: lv_date(8)       TYPE c,
            lv_file_name     TYPE string.
      DATA: lc_file_prefix(14) TYPE c VALUE 'eSFA_GL_CandC_',
            lc_file_suffix(4)  TYPE c VALUE '.txt'.
      lv_date = gv_to_date.
      CONCATENATE lc_file_prefix lv_date lc_file_suffix INTO lv_file_name.
      gv_file_name = lv_file_name.
    ENDFORM.                    " build_file_name
    *&      Form  download_on_application_server
          Routine to download file on application server
    FORM download_on_application_server.
      DATA : lv_command   TYPE string,
             lv_lines     TYPE i.
      lv_command   = 'ZFII0431'.
    File should be downloaded only if it is not empty
      IF gi_bseg IS NOT INITIAL.
    Open file for output in text mode
        OPEN DATASET gv_server_file_name FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
        IF sy-subrc IS NOT INITIAL.
          WRITE / 'File could not be open.'(m01).
          EXIT.
        ENDIF.        "IF sy-subrc IS NOT INITIAL
        DESCRIBE TABLE gi_posting_summary LINES lv_lines.
        LOOP AT gi_posting_summary INTO gwa_posting_summary.
          IF sy-tabix <> lv_lines.
          Transfer data to application server
            TRANSFER gwa_posting_summary TO gv_server_file_name.
          ELSE.
          Transfer data to application server with out end of line
            TRANSFER gwa_posting_summary TO gv_server_file_name NO END OF LINE.
          ENDIF.
        ENDLOOP. " LOOP AT gi_posting_summary INTO gwa_posting_summary
    Close file for output in text mode
        CLOSE DATASET gv_server_file_name.
        IF sy-subrc IS NOT INITIAL.
          WRITE / 'File could not be close.'(m02).
          EXIT.
        ELSEIF sy-subrc IS INITIAL.
          WRITE : / 'File Name:', gv_file_name .
          WRITE : / 'File Downloaded to Application Server successfully.'(m04).
        Call the OS command to run Shell script.
          PERFORM change_file_status USING lv_command.
        ENDIF.
      ENDIF.
    ENDFORM.                    " download_on_application_server
    *&      Form  clear_memory
          Clear all global variables
    FORM clear_memory .
      REFRESH: gi_bkpf           ,
               gi_bseg           ,
               gi_posting_summary.
      REFRESH: gr_date.
      CLEAR: gwa_bseg           ,
             gwa_posting_summary,
             gwa_date           .
      CLEAR: gv_from_date       ,
             gv_to_date         ,
             gv_effective_date  ,
             gv_posting_amount  ,
             gv_file_name       ,
             gv_server_file_name.
    ENDFORM.                    " clear_memory
    ***INCLUDE ZFI_GET_PHYSICAL_PATH .
    *&      Form  get_physical_path
          Routine for compile physical path of file on Appln. Server
          from logical path and desired filename.
         -->P_P_L_PATH  text
         -->P_GV_FILE_NAME  text
         -->P_GC_OK  text
         <--P_GV_SERVER_FILE_NAME  text
    FORM get_physical_path  USING    p_p_l_path      TYPE any
                                     p_gv_file_name  TYPE any
                                     p_gc_ok         TYPE any
                            CHANGING p_gv_server_file_name    TYPE any.
      CALL FUNCTION 'FILE_GET_NAME_USING_PATH'
        EXPORTING
          client                     = sy-mandt
          logical_path               = p_p_l_path
          operating_system           = sy-opsys
          file_name                  = p_gv_file_name
          eleminate_blanks           = p_gc_ok
        IMPORTING
          file_name_with_path        = p_gv_server_file_name
        EXCEPTIONS
          path_not_found             = 1
          missing_parameter          = 2
          operating_system_not_found = 3
          file_system_not_found      = 4
          OTHERS                     = 5.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
    ENDFORM.                    " get_physical_path

  • Runtime Error in OPEN DATASET

    Dear All,
    I am trying to upload a text file in application server. But I am getting the run time error which says-
    " For the statement
        "TRANSFER f TO ..."
    only character-type data objects are supported at the argument position
    "f".
    In this case. the operand "f" has the non-character-type "u". The
    current program is a Unicode program. In the Unicode context, the type
    'X' or structures containing not only character-type components are
    regarded as non-character-type."
    If I remove the quantity fields then the error does not happen. But I have to take quantity fields also. Plz tell me what to do. My code is,
    DATA FILENAME like rlgrap-filename VALUE 'MIGO_VALUE.txt'.
    TABLES VBAK.
    DATA D_MSG_TEXT(50).
    DATA : BEGIN OF it_mseg OCCURS 0,
           mblnr TYPE mseg-mblnr,
           mjahr TYPE mseg-mjahr,
           matnr TYPE mseg-matnr,
    *       erfmg TYPE mseg-erfmg,
           werks TYPE mseg-werks,
           lgort TYPE mseg-lgort,
           END OF it_mseg.
    DATA wa LIKE it_mseg.
    SELECT mblnr mjahr matnr werks lgort FROM mseg INTO CORRESPONDING FIELDS OF TABLE it_mseg WHERE bwart = '101'.
    SORT it_mseg BY mblnr.
    OPEN DATASET FILENAME FOR OUTPUT IN TEXT MODE ENCODING DEFAULT
                          MESSAGE D_MSG_TEXT.
    if sy-subrc eq 0.
    message 'File created succesfully in SAP System'(002) type 'S'.
    endif.
    IF SY-SUBRC NE 0.
      WRITE: 'File cannot be opened. Reason:', D_MSG_TEXT.
      EXIT.
    ENDIF.
    * Transferring Data
    LOOP AT it_mseg INTO wa.
    TRANSFER wa to filename.
    ENDLOOP.
    * Closing the File
    CLOSE DATASET FILENAME.
    Thanks,
    Tripod.

    Thanks Sri for your help. I tried to apply the logic, but the  error i am getting here is -
    "IT_MSEG-ERFMG" must be a character-like data object (data type C, N,D, T, or STRING) STRING).
    Same case here, if I remove ERFMG field, i do not get such error.
    data ld_string type string.
    LOOP AT it_mseg INTO wa.
      CONCATENATE it_mseg-mblnr it_mseg-mjahr it_mseg-matnr it_mseg-erfmg it_mseg-werks it_mseg-lgort INTO ld_string.
         endloop.
    With regards,
    Tripod.

  • Physical file location in SAP when OPEN DATASET command is used

    Hi,
    I have used below sample code from SAP help in my program. If you notice, I have not specified the file path however I am able to open and read this file whenever I want. Could anybody let me know where exactly is this file physically located. I have tried SP11( Temse objects) but no use.
    DATA: file   TYPE string VALUE `test.dat`,
          result TYPE string.
    OPEN DATASET file FOR OUTPUT IN TEXT MODE
                                 ENCODING DEFAULT.
    TRANSFER `1234567890` TO file.
    CLOSE DATASET file.
    OPEN DATASET file FOR UPDATE IN TEXT MODE
                                 ENCODING DEFAULT .
    TRANSFER `ABCD` TO file.
    CLOSE DATASET file.
    OPEN DATASET file FOR INPUT IN TEXT MODE
                                ENCODING DEFAULT .
    WHILE sy-subrc = 0.
      READ DATASET file INTO result.
      WRITE / result.
    ENDWHILE.
    CLOSE DATASET file.
    Regards
    Kasi

    Hi,,
    In the transaction AL11 go to the directory  DIR_TEMP... you can find your file there
    Regards,
    Siddarth

  • Problem with file in open dataset

    Hi experts ,
    i m  getting output in a standard way . all the fields are displaying in one column .
    this is my code .
      DATA: L_DATA LIKE RLGRAP-FILENAME VALUE '/usr/sap/dev/sys/global/substanc' .
      OPEN DATASET L_DATA FOR OUTPUT IN TEXT MODE ENCODING DEFAULT  .
      IF SY-SUBRC <> 0.
        MESSAGE E208(00) WITH 'Error Opening File'.
      ENDIF.
      LOOP AT I_DOWNLOAD INTO I_WA.
        TRANSFER I_WA-WERKS TO L_DATA.
        TRANSFER I_WA-MATNR TO L_DATA .
        TRANSFER I_WA-MAKTX TO L_DATA.
        TRANSFER I_WA-MEINS TO L_DATA.
        TRANSFER I_WA-PQTY TO L_DATA.
        TRANSFER I_WA-FKLMG1 TO L_DATA.
        TRANSFER I_WA-DQTY TO L_DATA.
        TRANSFER I_WA-DOFORCAST TO L_DATA.
        TRANSFER I_WA-DUFORCAST TO L_DATA.
        TRANSFER I_WA-WAQTY TO L_DATA.
        TRANSFER I_WA-OFORCAST TO L_DATA.
        TRANSFER I_WA-UFORCAST TO L_DATA.
      ENDLOOP.
      CLOSE DATASET L_DATA.
      IF SY-SUBRC <> 0.
        MESSAGE E208(00) WITH 'Error Closing File'.
      ENDIF.
    Thanks,
    Ashish Gupta
    Moderator Message: Basic and Duplicate Post.
    Edited by: kishan P on Dec 10, 2010 3:05 PM

    Hi Sravan,
    Thanks for replay .
    I did the same but  i was getting error message .
    "I_WA" cannot be a table, a reference, a string, or contain any of
    these objects. any of these objects
    This is my internal table and work area definition.
    DATA : I_DOWNLOAD TYPE TABLE OF TY_DOWNLOAD WITH HEADER LINE,
           I_WA TYPE TY_DOWNLOAD.
    Thanks ,
    Ashish Gupta

  • Saving .csv into internal table - using dataset (',' comes between data)

    Hi experts,
    I need to save .csv from application server to internal table.
    i am using the below code.
    gt_raw and gwa_raw are dxrawdata format.
    OPEN DATASET gv_pfile FOR INPUT IN TEXT MODE ENCODING DEFAULT.
    *--- Display error messages if any.
      IF sy-subrc NE 0.
        WRITE:/ 'FILE UPLOAD FAILED - ERROR NO. : ', sy-subrc.
        EXIT.
      ELSE.
        DO.
          READ DATASET gv_pfile INTO gwa_raw.
          IF sy-subrc NE 0.
            EXIT.
          ELSE.
            APPEND gwa_raw TO gt_raw.
            CLEAR gwa_raw.
          ENDIF.
        ENDDO.
    *--Close the Application server file (Mandatory).
        CLOSE DATASET gv_pfile.
      ENDIF.
      DELETE DATASET gv_pfile.
      LOOP AT gt_raw into gwa_raw.
        IF SY-TABIX > 1.
          SPLIT gwa_raw at ',' into gwa_cust-cust_code
                                    gwa_cust-cust_name
                                    gwa_cust-grp_name
          APPEND gwa_cust TO gt_cust.
          CLEAR: gwa_cust, gwa_raw.
        ENDIF.
      ENDLOOP.
    My program works fine.
    But when the gwa_cust-grp_name contains the value for eg. -> panasonic co., ltd.
    it takes till panasonic co., only
    and leaves ltd. as i am using SPLIT command.
    is there any other way to do this.
    plz help me to solve this issue.
    thanks.

    Hi,
    I notice you have marked the message as answered, but I just wanted to let you know there is a solution. The trick is to parse into an internal table and then to find and reassemble fields that were split because they contgain a comma. The ABAP program below is a commented example.
    Rgds,
    Mark
    REPORT  zcsv_parse.
    DATA:
      tokens       TYPE i.
    TYPES: BEGIN OF ty_result,
      company      TYPE char20,
      compnr       TYPE i,
      city         TYPE char30,
      country      TYPE char30,
    END OF ty_result.
    DATA:
      gt_rawtab    TYPE TABLE OF string,
      gw_rawtab    LIKE LINE OF gt_rawtab,
      gt_result    TYPE TABLE OF ty_result,
      gw_result    LIKE LINE OF gt_result,
      gt_parse     TYPE TABLE OF string,
      gw_parse     LIKE LINE OF gt_parse.
    DEFINE %csvline.
      gw_rawtab = &1.
      append gw_rawtab to gt_rawtab.
    END-OF-DEFINITION.
    START-OF-SELECTION.
    * Create CSV lines, some with a comma inside a token
      %csvline '"CompanyOne NV",500,"Antwerp","Belgium"'.
      %csvline '"CompanyTwo,Inc",600,"New York,NY","USA"'.
      %csvline '"CompanyThree,Ltd",700,"Sydney,NSW","Australia"'.
    * Parse the raw CSV
      LOOP AT gt_rawtab INTO gw_rawtab.
        REFRESH gt_parse.
        SPLIT gw_rawtab AT ',' INTO TABLE gt_parse.
        DESCRIBE TABLE gt_parse LINES tokens.
    *   If extra commas: token count higher than field count
        IF tokens > 4.
          PERFORM reassemble.
        ENDIF.
    *   At this point each entry in GT_PARSE contains exactly
    *   one result field => build the result table
        LOOP AT gt_parse INTO gw_parse.
    *     Strip quotes from text fields
          REPLACE ALL OCCURRENCES OF '"' IN gw_parse WITH ''.
          CASE sy-tabix.
            WHEN 1. gw_result-company = gw_parse.
            WHEN 2. gw_result-compnr = gw_parse.
            WHEN 3. gw_result-city = gw_parse.
            WHEN 4. gw_result-country = gw_parse.
          ENDCASE.
        ENDLOOP.
        APPEND gw_result TO gt_result.
      ENDLOOP.
    * Show the formatted result
      LOOP AT gt_result INTO gw_result.
        WRITE: / gw_result-company, gw_result-compnr,
                 gw_result-city, gw_result-country.
      ENDLOOP.
    *&      Form  reassemble
    *       Merges tokens that were split because they contain a comma
    FORM reassemble.
      DATA: lastpos    TYPE i,
            lastchar   TYPE c,
            currtoken  LIKE sy-tabix,
            nexttoken  LIKE sy-tabix,
            gw_next    LIKE gw_parse.
      LOOP AT gt_parse INTO gw_parse.
        lastpos  = STRLEN( gw_parse ) - 1.
        lastchar = gw_parse+lastpos(1).
    *   Token starts with quote but does not end with one =>
    *   must merge with the next token
        IF gw_parse+0(1) = '"' AND lastchar <> '"'.
          currtoken = sy-tabix.
          nexttoken = sy-tabix + 1.
          READ TABLE gt_parse INTO gw_next INDEX nexttoken.
          CONCATENATE gw_parse gw_next INTO gw_parse SEPARATED BY ','.
          MODIFY gt_parse FROM gw_parse INDEX currtoken.
          DELETE gt_parse INDEX nexttoken.
        ENDIF.
      ENDLOOP.
    ENDFORM.                    "reassemble

  • How to open a pdf file using OPEN DATASET

    Im trying to convert a pdf into binary format. So im trying to read the contents of the pdf into a XSTRING. Using the FM 'SCMS_XSTRING_TO_BINARY' i can convert the XSTRING to binary format.
    How to open a pdf file using OPEN DATASET and transfer its contents in a XSTRING variable.
    What i've tried is....
    DATA: f_name type string value 'C:\rep_output_pdf.pdf',
          x1 type xstring,
          LT_DATA TYPE STANDARD TABLE OF X255.
    OPEN DATASET f_name FOR input IN BINARY MODE.
    READ DATASET f_name INTO x1.
    CLOSE DATASET f_name.
    CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
        EXPORTING
          BUFFER     = x1
        TABLES
          BINARY_TAB = LT_DATA.
    Im getting a short dump .
    Short text: The file is not open.
    Plz help me out.

    Hello Rajesh,
    You are trying to do use OPEN DATASET with a local file. NOT POSSIBLE
    You have to have the file in the app server to use OPEN DATASET.
    BR,
    Suhas

Maybe you are looking for

  • IAS: Java Classes not found Error

    Hello, [oracle@Linux2005 bin]$ ORACLE_HOME=$ORACLE_HOME5 [oracle@Linux2005 bin]$ ./rwserver.sh server=RepSRV batch=yes [oracle@Linux2005 bin]$ ./rwserver server=RepSRV REP-0133: Java Classes not found ==== 1) Getting a REP-0133: Java Classes not foun

  • GetString returning 0.0

    How do I solve the problem with ResultString.getString returning 0.0 instead of 0. I retrieve data from a column of type number(10). Rickard Eneroth WM-data [email protected] null

  • Budget  Exemption

    Hi , In our Purchase oder we have a net amount for material on which excise duty.cenvat,E cess are paid during the budget check system makes check for the whole amount I want it shuld check only for the net value as the customer is getting modvat aga

  • ACS for 802.1x Authentication using RSA Tokens and Microsoft PEAP

    Has anyone been able to configure 802.1x authentication on Windows XP machines using RSA tokens using Cisco ACS as the RADIUS server? I have come up with bunch of incompatibilities between the offered support e.g. 1. Microsoft PEAP does not support a

  • BusinessObjects XI 3.0 - Central Management Console Login Fail

    Post Author: iamhimhim CA Forum: Deployment Hello Everyone, I'm a beginner of BusinessObjects, I got a problem after I installed this software and try to login the CMC I got the following error message return, since I use default setting during setup